如何跟踪使用 PHP Swift Mailer 发送的邮件? [英] How can I keep track of mail sent using PHP Swift Mailer?

查看:29
本文介绍了如何跟踪使用 PHP Swift Mailer 发送的邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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.

我的代码:

<?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() 方法发送邮件,它为我提供了已发送邮件的数量,但它没有为我提供已发送的电子邮件列表.怎么可能,有没有可用的插件或功能?

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?

使用 Logger 插件会给我日志,但我无法从中读取.

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

推荐答案

您可以通过引用 batchSend() 传递变量来获取被拒绝的电子邮件地址数组,供系统填充在:

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

然后你可以array_diff()从你的$to_mail数组中获取成功的那些.

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

这篇关于如何跟踪使用 PHP Swift Mailer 发送的邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆