2010-09-18 82 views
0

我正在使用PHP Swift Mailer向一組用戶發送批量郵件。但我無法跟蹤發送的郵件。如何跟蹤使用PHP Swift Mailer發送的郵件?

我的代碼:

<?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); 
?> 

我使用batchSend()方法來發送郵件,這給了我已發送的郵件的數量,但它不給我,一直電子郵件列表發送。怎麼可能,有沒有插件或功能可用?

使用Logger插件會給我日誌,但我無法從中讀取。

回答

2

你可以得到電子郵件地址的排列,它是通過引用傳遞變量batchSend()該系統填補了拒絕:

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

然後你就可以array_diff()那些從$to_mail陣列來獲得成功的人。

+0

我試過,通過傳遞失敗作爲參數,並試圖發送郵件[email protected]_domain.com,但沒有返回我任何失敗..數組爲空.. – 2010-09-18 06:51:41

+0

你使用哪個版本的Swiftmailer?如果是v3,那麼你應該使用'$ mailer-> getFailedRecipients();' – Fanis 2010-09-18 07:02:54

+0

我使用的是4.0.6版本,將$ mailer-> getFailedRecipients();在版本4工作?? – 2010-09-18 07:10:30