批量发送包含自定义内容的电子邮件
我想使用 SwiftMailer 发送批量邮件,但只是想知道最好的选择是什么。问题是电子邮件内容需要自定义,即顶部会有一个称呼,以及一个自定义链接。
这是我当前的 OOP 代码:
foreach($suppliers as $supplier)
{
$quote=new Quote();
$quote->enquiry_id=$enquiry->id;
$quote->supplier_id=$supplier->id;
if($quote->save())
{
$supplier_emails[]=$supplier->email;
}
}
$message=new SwiftMailMessage;
$message->setTo($supplier_emails);
$message->setFrom($params['adminEmailFromAddress'] => $params['adminEmailFromName']);
$message->setBody('Here is the message itself')
App::app()->mail->batchSend($message);
我正在使用 SwiftMailer 的容器。正如您所看到的,我可以轻松指定要发送消息的电子邮件地址数组。我现在如何自定义内容?我需要在内容中包含的变量是 $supplier->name 和 $supplier->link。
就我个人而言,除了在 foreach() 循环中单独发送每封电子邮件之外,我不知道如何做到这一点。如果是这样的话,那么使用 PHP 内部的 mail() 函数不是更好吗?
I want to send out batch mails using SwiftMailer but just wondering what the best option for this would be. The problem is the email content needs to be customized, i.e. there will be a salutation at the top, and a custom link.
Here is my current OOP code:
foreach($suppliers as $supplier)
{
$quote=new Quote();
$quote->enquiry_id=$enquiry->id;
$quote->supplier_id=$supplier->id;
if($quote->save())
{
$supplier_emails[]=$supplier->email;
}
}
$message=new SwiftMailMessage;
$message->setTo($supplier_emails);
$message->setFrom($params['adminEmailFromAddress'] => $params['adminEmailFromName']);
$message->setBody('Here is the message itself')
App::app()->mail->batchSend($message);
I am using a container for SwiftMailer. So as you can see, I can easily specify an array of email address to send the message to. How can I now customize the content? The variables I need to include in the content are $supplier->name and $supplier->link.
Personally I can't see how this can be done, other than sending each email individually in the foreach() loop. IF that is the case, then is it not better to just use the internal PHP mail() function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用装饰器插件:
http://swiftmailer.org/docs/decorator-plugin
You could try using the Decorator plugin:
http://swiftmailer.org/docs/decorator-plugin