编程语言
首页 > 编程语言> > php – Swiftmailer 4不会将退回视为$failedRecipients

php – Swiftmailer 4不会将退回视为$failedRecipients

作者:互联网

我正在尝试此代码(从http://swiftmailer.org/docs/sending.html):

    require_once 'lib/swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('localhost', 25);

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setBody('Here is the message itself')
  ;

//Send the message
$failedRecipients = array();
$numSent = 0;
$to = array('receiver@domain.org', 'other@baddomain.org' => 'A name');

foreach ($to as $address => $name)
{
  $message->setTo(array($address => $name));
  $numSent += $this->send($message, $failedRecipients);
}

printf("Sent %d messages\n", $numSent);

问题是,如果我向坏域发送电子邮件swiftmailer将其识别为正确的已发送电子邮件且$failedRecipients为空.在我的邮箱中,我收到了失败通知.

为什么Swiftmailer不能将此邮件识别为失败,并且没有填充$failedRecipients Array?

解决方法:

Swiftmailer只关注将电子邮件传递给邮件服务器.其他一切与Swiftmailer无关.

你得到的是退回邮件,你需要自己处理它们,因为电子邮件本身实际上是一个语法邮件地址,没有被第一台服务器拒绝.

btw是任何其他邮件库甚至PHP邮件功能的情况.您可能正在寻找退回处理应用程序或代码.

相关:Bounce Email handling with PHP?

标签:swiftmailer,php,sendmail
来源: https://codeday.me/bug/20191003/1845769.html