【问题标题】:Limit email sending retries in swiftmailer在 swiftmailer 中限制电子邮件发送重试
【发布时间】:2016-05-13 09:04:18
【问题描述】:

我使用 Swiftmailer 编写了以下批量电子邮件发送脚本(使用它来传递时事通讯)。通常一切正常,除了几个用户,他们的电子邮件服务器有问题,不断拒绝电子邮件(例如,由于收件箱已满,未能验证反向 DNS 条目,......)。问题是 Swiftmailer 会无限次重试发送到这些电子邮件(直到服务器重新启动)。

有什么方法可以限制重试次数吗?

我读到Swift_FileSpool 类有setRetryLimit 函数,默认值为10 重试。但我不确定如何使用它。此外,由于某种原因,默认重试限制似乎不适用。

<?php

$emails=get_to_emails();//list of emails

require_once(SWIFTMAILER_KELIAS."swift_required.php");

$swMailer=Swift_Mailer::newInstance(Swift_MailTransport::newInstance());
$swMailer->registerPlugin(new Swift_Plugins_ThrottlerPlugin(10,Swift_Plugins_ThrottlerPlugin::MESSAGES_PER_MINUTE));

$message=Swift_Message::newInstance();
$message->setContentType('text/html');
$message->setCharset('UTF-8');

$message->setSender(array(ADMIN=>ADMIN_NAME));
$message->setFrom(array(ADMIN=>ADMIN_NAME));
$message->setSubject("subject");
$message->setBody($text,'text/html');
$message->addPart(strip_tags(str_replace(array("</h1>","</p>","</br>","<br>","<br/>"),array("</h1>\r\n","</p>\r\n","<br/>\r\n","<br/>\r\n","<br/>\r\n"),$text)),'text/plain');

foreach($emails as $email) {
    $message->setTo($email);
    $swMailer->send($message);
}

?>

【问题讨论】:

    标签: php swiftmailer


    【解决方案1】:

    您的代码显示您正在使用 SwiftMailers Swift_MailTransport() 作为传输器类,它基于 PHP 的内置 mail() 函数。这是非常便携的,但可能会产生不可预测的结果,并且提供的反馈非常弱。

    mail() 函数通常将邮件放入本地邮件传递代理的队列中。检查服务器的 smtp 配置以更改行为,例如重试间隔等。

    为了更直接地控制您的脚本行为,您可以考虑切换到Swift_SmtpTransport()

    【讨论】:

      猜你喜欢
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-05
      相关资源
      最近更新 更多