如何解决PHPMailer中的异常会停止整个脚本,而不仅仅是继续
我正在使用PHPMailer进行新闻稿发送作业。有时,附件或某些其他详细信息不适用于一个特定的电子邮件收件人。在这种情况下,它会引发一个异常,该异常会写入我自己的日志文件中,这很不错,因为它经常清楚地指出出了什么问题。
问题是,完整的脚本停止了,并且所有其他可能具有正确设置的电子邮件也没有发送。
我如何配置它以便在PHPMailer引发异常时不停止整个脚本,而继续直到发送了具有正确设置的for循环中的所有电子邮件?
read * from email_receipients
for each {
$mail = new PHPMailer(true);
try {
//SMTP settings
//..
$mail->Subject = $mailbody_subject;
$mail->Body = $mailbody_html;
$mail->AltBody = $mailbody_text;
$mail->send();
} catch (phpmailerException $ep) {
$ep_mail_send_message = $ep->getMessage();
$ep_mail_send_code = $ep->getCode();
//writes the $ep error messages to a log file
} catch (Exception $e) {
$e_mail_send_message = $e->getMessage();
$e_mail_send_code = $e->getCode();
//writes the $e error messages to a log file
}
} //closes the for each loop
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。