如何跟踪使用 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 插件会给我日志,但我无法从中读取日志。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过引用
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.