views:

56

answers:

1

I am using PHP Swift Mailer to send a bulk mail to a set of users. But I am not able to keep track of sent mail.

My code:

<?php 
require_once("includes/database.class.php");
require_once("lib/swift_required.php"); 
$con=DBClass::getConnection();
$db=DBClass::getDatabase($con);

$login_id="myloginname";
$password="mypassword";

$to_mail; //list of people 

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl") 
          ->setUsername($login_id)
          ->setPassword($password);

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


 //Rate limit to 25 emails per-minute
$mailer->registerPlugin(new Swift_Plugins_ThrottlerPlugin(
25, Swift_Plugins_ThrottlerPlugin::MESSAGES_PER_MINUTE
        ));

//Create a message
        $message = Swift_Message::newInstance($subject)
          ->setFrom($login_id)
          ->setTo($to_mail)
          ->setBody($body,
                    'text/html'
                    ); 

$numSent=$mailer->batchSend($message);
?>

I am using batchSend() method to send mail, which gives me the count of mail that has been sent, but it is not giving me the list of email that has been sent. How can it be possible, is there any plugin or function available?

Using Logger plugin will give me the log, but I am unable to read from that.

+1  A: 

You can get an array of email addresses that were rejected by passing a variable by reference to batchSend() for the system to fill in:

http://swiftmailer.org/docs/failures-byreference

Then you can array_diff() those from your $to_mail array to get the succesful ones.

Fanis
i have tried that, by passing failure as a parameter, and tried to send mail to error_man1212121212@error_domain.com but didnt return me any failure.. the array was null..
Harish Kurup
Which version of Swiftmailer are you using? If it's v3 then you should use `$mailer->getFailedRecipients();`
Fanis
i am using the version 4.0.6, will $mailer->getFailedRecipients(); work in version 4??
Harish Kurup
No that's for v3. For v4 my initial answer should be used. According to http://swiftmailer.lighthouseapp.com/projects/21527/tickets/123-failures-does-not-work $failures will include ones that your SMTP server rejected instantly (eg failed to connect, or illegal characters in email address), not ones that bounced along the way (eg unknown user). The same ticket reply suggests http://phpmailer.worxware.com/index.php?pg=bmh for handling those. More here: http://groups.google.com/group/swiftmailer/browse_thread/thread/fc1dd03e320b1cbb?pli=1
Fanis
@Fanis Thank you very much...i will read that and let you know...thank u!
Harish Kurup
Cheers, good luck!
Fanis