PHPmailer duplicate email issue - conditional statement with $mail->Send()

偶尔善良 提交于 2019-12-01 22:02:07

When you put $mail->Send() in your conditional, you're actually calling it again, sending another message, and checking if that second message was sent.

If you just keep

if ($mail->Send()) {  
    echo 'Message has been sent.';  
} else {  
    echo "Mailer Error: " . $mail->ErrorInfo;   
}

and get rid of the original, unconditional Send call, you should be fine.

Alternatively, if it's clearer for you or if you need to do some processing elsewhere that depends on whether the message was successfully sent, you could do the essentially equivalent:

$status = $mail->Send();
if ($status) {  
    echo 'Message has been sent.';  
} else {  
    echo "Mailer Error: " . $mail->ErrorInfo;   
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!