duanfen1992 2016-05-13 09:04
浏览 20
已采纳

限制在swiftmailer中发送重试的电子邮件

I have written the following bulk email sending script using Swiftmailer (using it to deliver newsletter). Usually everything works fine except couple of users, who have problematic email servers, which constantly reject emails (e.g., due to full inbox, failure to verify reverse DNS entries, ...). The problem is that the Swiftmailer retries sending to those emails infinitely many times (until server is restarted).

Is there a some way to limit amount of retries?

I have read that Swift_FileSpool class has setRetryLimit function and that the default value is 10 retries. But I am not sure how do I use that. Also it seems that the default retry limit does not apply for some reason.

<?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>
","</p>
","<br/>
","<br/>
","<br/>
"),$text)),'text/plain');

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

?>
  • 写回答

1条回答 默认 最新

  • dtu1747 2016-05-16 07:37
    关注

    Your code shows that you're using SwiftMailers Swift_MailTransport() as transporter class, which is based on PHP's built-in mail() function. This is very portable, but has potentially unpredictable results and provides extremely weak feedback.

    The mail() function usually puts the mail into the queue of the local mail delivery agent. Check your smtp configuration of your server to change the behaviour, p.e. retry intervals etc.

    In order to have more direct control over your scripts behaviour, you might consider switching to Swift_SmtpTransport().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#linux#的问题(输入输出错误):出现这个界面接着我重新装系统,又让修电脑的师傅帮我扫描硬盘(没有问题)用着用着又卡死(相关搜索:固态硬盘)
  • ¥15 cv::resize不同线程时间不同
  • ¥15 web课程,怎么做啊😭没好好听课 根本不知道怎么下手
  • ¥15 做一个关于单片机的比较难的代码,然后搞一个PPT进行解释
  • ¥15 python提取.csv文件中的链接会经常出现爬取失败
  • ¥15 数据结构中的数组地址问题
  • ¥15 maya的mel里,怎样先选择模型A,然后利用mel脚本自动选择有相同名字的模型B呢。
  • ¥15 Python题,根本不会啊
  • ¥15 会会信号与系统和python的来
  • ¥15 关于#python#的问题