当send()失败时,如何检查SwiftMailer v4中的实际错误


How do you check for the actual error in SwiftMailer v4 when send() fails

使用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";
}