Getting Failures By-reference
Collecting delivery failures by-reference with the send() or batchSend() methods is as simple as passing a variable name to the method call.
To get failed recipients by-reference:
Pass a by-reference variable name to the send() or batchSend()
methods of the Mailer class.
If the Transport rejects any of the recipients, the culprit addresses will be added to the array provided by-reference.
Note:
If the variable name does not yet exist, it will be initialized as an empty array and then
failures will be added to that array. If the variable already exists it will be type-cast to
an array and failures will be added to it.
$mailer = Swift_Mailer::newInstance( ... );
$message = Swift_Message::newInstance( ... )
->setFrom( ... )
->setTo(array(
'receiver@bad-domain.org' => 'Receiver Name',
'other@domain.org' => 'A name',
'other-receiver@bad-domain.org' => 'Other Name'
))
->setBody( ... )
;
//Pass a variable name to the send() method
if (!$mailer->send($message, $failures))
{
echo "Failures:";
print_r($failures);
}
/*
Failures:
Array (
0 => receiver@bad-domain.org,
1 => other-receiver@bad-domain.org
)
*/
Parent topic: Finding out Rejected Addresses