$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}";
}
You don't show all of your code, but I'd guess that you have not enabled exceptions, so you effectively have no error checking. Make sure that your PHPMailer instantiation looks like this:
$mail = new PHPMailer(true);
You need that true
parameter to enable exceptions. You don't need to check the return status of send()
if you have exceptions enabled because it will throw an exception if there is a problem.