我使用phpMailer发送批量电子邮件,有些电子邮件正在反弹,我如何获得硬退回的电子邮件ID。
我是PHP的新手,我在一些网站上发现我会得到像
这样的回复500 - The server could not recognize the command due to a syntax error.
501 - A syntax error was encountered in command arguments.
502 - This command is not implemented.
503 - The server has encountered a bad sequence of commands.
504 - A command parameter is not implemented.
550 - The requested command failed because the user's mailbox was unavailable (for example because it was not found, or because the command was rejected for policy reasons).
551 - The recipient is not local to the server. The server then gives a forward address to try.
552 - The action was aborted due to exceeded storage allocation.
553 - The command was aborted because the mailbox name is invalid.
554 - The transaction failed. Blame it on the weather.
但我没有说明如何获得此回复?
答案 0 :(得分:1)
当您运行“Send()”方法时,您可以检查“ErrorInfo”属性:
$mail = new PHPMailer();
...
if(!$mail->Send())
{
echo "Message could not be sent.";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
或
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
...
try
{
...
$mail->Send();
}
catch (phpmailerException $e)
{
echo $e->errorMessage(); // Error messages from PHPMailer
}
catch (Exception $e)
{
echo $e->getMessage(); // Something else
}