$mail->SMTPDebug = 2; will display all the things happened while we send mail.
It also displays SERVER -> CLIENT: 250 2.0.0 Ok: queued, which means all the checks were true (no issues in host/pot, etc) and mail has been sent.
Can we validate this in if condition?
Like
if("SERVER -> CLIENT: 250 2.0.0 Ok: queued" == "SERVER -> CLIENT: 250 2.0.0 Ok: queued"){
echo "sent";
} else {
echo "error"; }
Because below code will always show sent if the host is also not correct. (tested, then I came here).
try {
$mail->IsSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->Host = "smtp.wrong.domain";
$mail->Port = 587;
$mail->AddAddress("*****");
$mail->Username="*****";
$mail->Password="*****";
$mail->SetFrom('*****','*****');
$mail->AddReplyTo("*****@*****.*****","*****");
$mail->Subject = "*****";
$mail->MsgHTML("Hi 587");
$mail->Send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
Aucun commentaire:
Enregistrer un commentaire