问题描述
||
使用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\";
}