PHP 群发邮件:一人一份还是所有人一份?

发布于 2024-10-17 11:35:38 字数 108 浏览 2 评论 0原文

使用 PHP 发送群发邮件时,最好向每个订阅者发送一封电子邮件(对所有电子邮件地址运行 for 循环),还是将所有内容以密件抄送方式添加到逗号分隔列表中,从而仅发送一封电子邮件?

谢谢。

When sending mass mails with PHP, is it better to send each subscriber an e-mail (running a for loop through all the e-mail addresses) or is it better to just add all in BCC in a comma separated list and thus sending only one e-mail?

Thank you.

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

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

发布评论

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

评论(4

少年亿悲伤 2024-10-24 11:35:38

SMTP 服务器上的 BCC 字段中的地址数量很可能受到限制(以避免垃圾邮件)。我会选择安全的路线并向每个订阅者发送一封电子邮件。如果需要,您还可以为每个订阅者自定义电子邮件。

另请注意,mail() 可能不是发送批量邮件的最佳方式(因为它每次调用时都会打开一个到 SMTP 服务器的新连接)。您可能需要查看 PEAR::Mail

There's a good chance the number of addresses in the BCC field is limited on the SMTP server (to avoid spamming). I'd go with the safe route and send an e-mail to each individual subscriber. That will also allow you to customize the e-mail for each subscriber if needed.

Also note that mail() is probably not the best way to send bulk mail (due to the fact that it opens a new connection to the SMTP server each time it's invoked). You may want to look into PEAR::Mail.

鹿港小镇 2024-10-24 11:35:38

最佳做法是向每个收件人发送一封电子邮件。

如果它是一个 Linux 邮件服务器,它可以处理大量的吞吐量,所以容量不应该成为问题,除非它是一个垃圾服务器!

如果它是共享网络服务器,您的主机可能会不高兴 - 如果是这种情况,我会将其分成块并分散发送。如果它是专用的,那么就按照你的意愿去做:)

Best practice is to send an email per recipient.

If it's a linux mail server, it can handle massive throughputs so volume should not be an issue unless it's a crap server!

If it's a shared webserver your host may not be happy - if this si the case I'd split it into chuncks and spread the send. If it's dedicated then do as you will :)

追风人 2024-10-24 11:35:38

如果密件抄送收件人之一的发送过程因某种原因失败(例如可能导致无法解析的域),则整个操作将被取消(在 99% 的情况下这是不需要的行为)。

如果您在 PHP 循环中发送电子邮件,即使其中一封电子邮件发送失败,其他电子邮件也会发送。

If the sending process for some reason failed (example cause might me unresolvable domain) for one of the BCC recipients, the whole operation would be canceled (which is in 99% of cases unwanted behavior).

I you send the emails in a PHP loop, even if one of the emails fails to send, other emails will be sent.

蘑菇王子 2024-10-24 11:35:38

正如其他人所说,每个收件人一封邮件更合适。

如果您希望库为您完成肮脏的工作,请尝试 SwiftMailer http://swiftmailer.org

这里是直接来自文档的示例:

require_once 'lib/swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('localhost', 25);

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('[email protected]' => 'John Doe'))
  ->setTo(array('[email protected]', '[email protected]' => 'A name'))
  ->setBody('Here is the message itself')
  ;

//Send the message
$numSent = $mailer->batchSend($message);

printf("Sent %d messages\n", $numSent);

/* Note that often that only the boolean equivalent of the
   return value is of concern (zero indicates FALSE)

if ($mailer->batchSend($message))
{
  echo "Sent\n";
}
else
{
  echo "Failed\n";
}

*/

它还有一个不错的 Antiflood 插件: http://swiftmailer.org/文档/antiflood-plugin-howto

As the others says one mail per recipient is the better fit.

If you want a library to do the dirty job for you, give a try to SwiftMailer http://swiftmailer.org

Here is an example directly from the docs:

require_once 'lib/swift_required.php';

//Create the Transport
$transport = Swift_SmtpTransport::newInstance('localhost', 25);

//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);

//Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('[email protected]' => 'John Doe'))
  ->setTo(array('[email protected]', '[email protected]' => 'A name'))
  ->setBody('Here is the message itself')
  ;

//Send the message
$numSent = $mailer->batchSend($message);

printf("Sent %d messages\n", $numSent);

/* Note that often that only the boolean equivalent of the
   return value is of concern (zero indicates FALSE)

if ($mailer->batchSend($message))
{
  echo "Sent\n";
}
else
{
  echo "Failed\n";
}

*/

It also has a nice Antiflood plugin: http://swiftmailer.org/docs/antiflood-plugin-howto

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