如何跟踪使用 PHP Swift Mailer 发送的邮件?

发布于 2024-09-19 12:41:54 字数 1171 浏览 8 评论 0原文

我正在使用 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 插件会给我日志,但我无法从中读取日志。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最初的梦 2024-09-26 12:41:54

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

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

然后你可以 array_diff() 来自你的 $to_mail< /code> 数组来获取成功的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文