开发者

How can I keep track of mail sent using PHP Swift Mailer?

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开发者_StackOverflow::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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜