getFailedRecipients()

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
bobo79
Forum Newbie
Posts: 1
Joined: Thu Jul 03, 2008 2:56 pm

getFailedRecipients()

Post by bobo79 »

Hi everyone,
I use swiftmailer version Swift-3.3.2-php5
I want to enable logging to catch the failed addresses.

Code: Select all

<?
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
 
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
$log =& Swift_LogContainer::getLog();
$log->setLogLevel(4);
 
 
echo '<pre>' . htmlentities($log->dump(true)) . '</pre>';
 
$message =& new Swift_Message("My subject", "My body");
 
$recipients =& new Swift_RecipientList();
$recipients->addTo("aaa@qq q.it");
$recipients->addTo("xxx@yy y.it");
 
$num_sent = $swift->send($message, $recipients, "me@my-domain.com");
 
echo "Message sent to $num_sent of 2 recipients";
 
echo "Failed recipients:<br />";
echo implode(" ,", $log->getFailedRecipients());
?>

this is result:

++ Log level changed to 4
Message sent to 2 of 2 recipientsFailed recipients:

where is the prblem, an error

thanks
Bobo
sinisa
Forum Newbie
Posts: 1
Joined: Tue Jul 08, 2008 2:49 pm

Re: getFailedRecipients()

Post by sinisa »

can't see log records before sending emails. Move line
echo '<pre>' . htmlentities($log->dump(true)) . '</pre>';
before or instead of this line
echo "Message sent to $num_sent of 2 recipients";
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: getFailedRecipients()

Post by Chris Corbyn »

Yes, you're trying to dump the log before Swift has actually done anything. Place the log dump after the sending portion of the script.
Post Reply