【发布时间】:2015-10-19 06:51:02
【问题描述】:
我想向地址列表发送一封电子邮件,但我希望每个人都收到带有他的电子邮件地址的电子邮件:(而不是扩散列表中的其他电子邮件地址)。
我正在使用 symfony 和 Swift 邮件。我的代码现在看起来像这样(它正在工作):
public function sendmail(Notification $notification, $alert){
$to = array();
foreach ($members as $member) {
$to[] = $member->getUser()->getEmail();
}
$html = $this->templating->render(
'PlatformBundle:Emails:email.html.twig',
array('alert' => $alert, 'notification' => $notification, 'user' => $this->user)
);
// Configure and send the mail
$message = \Swift_Message::newInstance()
->setSubject('an email ')
->setFrom($this->sender_email)
->setCc($this->user->getEmail())
->setTo($to)
->setBody($html, 'text/html');
$mailStatus = $this->mailer->send($message);
}
我有 2 个解决方案(我不喜欢它们!)。
使用密件抄送 (Sending to multiple Email addresses but displaying only one C#) 但它使我的电子邮件看起来像垃圾邮件
-
循环发送相同的电子邮件给每个成员(似乎真的很消耗服务器资源)
public function sendmail(Notification $notification, $alert){ $to = array(); foreach ($members as $member) { $to[] = $member->getUser()->getEmail(); $html = $this->templating->render( 'PlatformBundle:Emails:email.html.twig', array('alert' => $alert, 'notification' => $notification, 'user' => $this->user) ); // Configure and send the mail $message = \Swift_Message::newInstance() ->setSubject('an email ') ->setFrom($this->sender_email) ->setCc($this->user->getEmail()) ->setTo($to) ->setBody($html, 'text/html'); $mailStatus = $this->mailer->send($message); }
这个循环好吗?
有更好的主意吗?
【问题讨论】:
-
Bcc 怎么样?为什么只有一个(可见)收件人的邮件会被视为垃圾邮件?
-
“但是,仅将电子邮件地址放在密件抄送字段中,而在收件人字段中没有地址(或您自己的地址),可能会导致邮件被某些垃圾邮件过滤器标记为垃圾邮件。”
-
密件抄送方法对密件抄送地址的数量有限制;并且确实有时在某些邮件服务器上被标记为垃圾邮件(我前段时间尝试过)。
-
你想一次性发送多少封邮件?
-
每个请求大约 50 到 100 封电子邮件。