使用 SwiftMailer 版本 4 发送邮件时有没有办法检查错误?我不是指获取被拒绝的收件人电子邮件列表,也不是仅仅知道 send() 是否有效。
我说的是了解发送过程中发生的实际错误——例如无法连接到 STMP 主机、登录错误等。
使用 SwiftMailer 版本 4 发送邮件时有没有办法检查错误?我不是指获取被拒绝的收件人电子邮件列表,也不是仅仅知道 send() 是否有效。
我说的是了解发送过程中发生的实际错误——例如无法连接到 STMP 主机、登录错误等。
只需检查 SwiftMailer 的 send() 或 batchSend() 命令的返回码,即可得到非零结果。如果您得到一个非零结果(即 TRUE),那么它成功连接并验证了您的 SMTP 服务。
从文档中:
//Send the message
$numSent = $mailer->send($message);
printf("Sent %d messages\n", $numSent);
// Note that often that only the boolean equivalent of the
// return value is of concern (zero indicates FALSE)
if ($mailer->send($message))
{
echo "Sent\n";
}
else
{
echo "Failed\n";
}