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

ぐ巨炮叔叔 提交于 2019-12-12 02:34:17

问题


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:


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.



来源:https://stackoverflow.com/questions/3740624/how-can-i-keep-track-of-mail-sent-using-php-swift-mailer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!