【问题标题】:Symfony swift_mail: send to multiple address but only display one address per emailSymfony swift_mail:发送到多个地址,但每封电子邮件仅显示一个地址
【发布时间】: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 个解决方案(我不喜欢它们!)。

  1. 使用密件抄送 (Sending to multiple Email addresses but displaying only one C#) 但它使我的电子邮件看起来像垃圾邮件

  2. 循环发送相同的电子邮件给每个成员(似乎真的很消耗服务器资源)

    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 封电子邮件。

标签: php symfony email


【解决方案1】:

循环确实是唯一的解决方案。

如果您有很多收件人,您将很快被标记为垃圾邮件(并被禁止)。您将需要通过一个专用的邮件平台(每次发送之间有一点时间),您可以自己编写代码(相当繁重的工作),或者周围有许多邮件平台作为服务,例如 MailChimp 或 MailJet。

这完全取决于要发送的邮件数量。每天最多 100 个可能没问题(尽管这是我脑海中的任意数字)。
超过某个阈值,并且根据您使用的邮件服务器(例如本地服务器或 gmail),您的 IP 或帐户可能会被禁止。例如,大多数电子邮件提供商每天都有邮件限制。

电子邮件服务有很多发送规则,例如,他们延迟发送电子邮件;他们使用多个域和地址发送;他们与主要的邮件提供商(gmail、yahoo...)合作,以确保他们的域不会被自动标记为垃圾邮件...

基本上,如果你真的想给很多人发很多邮件,我真的不建议你自己做。警告太多了。

【讨论】:

  • 感谢您的评论。我在我的问题中添加了我的循环。我应该设置发送之间的时间吗?
  • 这取决于要发送的邮件数量。每天最多大约 100 个可能没问题。超过某个阈值,并且取决于您使用的邮件服务器(例如本地服务器或 gmail),您的 IP 或帐户可能会被禁止。例如,大多数电子邮件提供商每天都有邮件限制。
  • 我刚刚尝试了上面的循环:我所有的电子邮件都被标记为垃圾邮件;我刚刚意识到在我的循环中我正在增加元素 $to...
  • 我已更新我的答案以添加有关此事的更多详细信息。
猜你喜欢
  • 2011-03-14
  • 1970-01-01
  • 2013-07-29
  • 1970-01-01
  • 2011-07-14
  • 1970-01-01
  • 1970-01-01
  • 2019-01-10
  • 2012-03-31
相关资源
最近更新 更多