Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
678 views
in Technique[技术] by (71.8m points)

php - Swiftmailer 4 does not retrieve bounces as $failedRecipients

I am trying this code (from 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('[email protected]' => 'John Doe'))
  ->setBody('Here is the message itself')
  ;

//Send the message
$failedRecipients = array();
$numSent = 0;
$to = array('[email protected]', '[email protected]' => 'A name');

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

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

The problem is that if I sent an email to a bad domain swiftmailer recognize it as a correct sent email and $failedRecipients is empty. In my mail box I have returned a failure notice.

Why does Swiftmailer not recognize this mail as as a failure, and does not populate $failedRecipients Array?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Swiftmailer only takes care to hand the email over to the mail-server. Everything else is not related to Swiftmailer.

What you get is a bounce message, and you need to process them on your own, because the email itself actually was a syntactically mail address that was not rejected by the first server.

That btw is the case for any other mailing library and even the php mail function. You might be looking for a bounce processing application or code.

Related: Bounce Email handling with PHP?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...