BCC 发送 PHP mail() 到邮件列表的方式与 TO 不同吗?

发布于 2024-10-19 13:40:27 字数 223 浏览 2 评论 0原文

我正在改进 PHP 邮件列表代码,该代码在循环中使用 mail(),同时迭代所有订阅者。该脚本用于显示“超出最大执行时间 30 秒”错误,我通过添加 set_time_limit(0); 解决了该错误。

现在没有错误,但发送 100 条消息花了大约七分钟。我有什么选择?

仅向 BCC 中的所有订阅者发送一条消息会有帮助吗?还是“在幕后”同样如此?

I'm improving PHP mailing list code that uses mail() in a loop while iterating through all subscribers. The script used to display a "Maximum execution time of 30 seconds exceeded" error which I solved by adding set_time_limit(0);.

Now there's no error but it took about seven minutes to send 100 messages. What are my options?

Will sending just a single message with all subscribers in BCC help or is it the same "behind the scenes"?

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

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

发布评论

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

评论(5

瑶笙 2024-10-26 13:40:27

以密件抄送方式发送给所有人将会更快很多。该代码将执行得更快,并且 mail() 将仅执行一次。

这是快速修复方法,但正如前面提到的,大型密件抄送列表是通往垃圾邮件文件夹的安全途径。然而,使用 mail() 也肯定会成为垃圾邮件的目的地。

如果您想真正改进它,请使用 SourceForge 的 PHPMailer 并通过 SMTP 发送(减少垃圾邮件命中)在 X 封邮件中使用 cron 一次。

PHP 文档指出:

注意:
值得注意的是,mail() 函数不适合循环中发送大量电子邮件。该函数为每封电子邮件打开和关闭一个 SMTP 套接字,效率不是很高。

要发送大量电子邮件,请参阅 » PEAR::Mail» PEAR::Mail_Queue 包。

Sending to all as BCC will be a lot faster. The code will execute faster and mail() will be executed only once.

This is the quick fix, but as mentioned, a large BCC list is a safe road to the spam folder. However, using mail() is a sure destination to spam too.

If you want to actually improve it, use PHPMailer from SourceForge and send via SMTP (less spam hits) using cron in batches of X emails once.

The PHP docs state:

Note:
It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.

For sending large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.

吃颗糖壮壮胆 2024-10-26 13:40:27

通过在密件抄送中指定所有订阅者来发送给他们应该会更快。不过,虽然对于某些私人环境来说这可能是一个不错的选择,但我不建议在公共网页/系统中这样做,因为许多人可能会认为此类电子邮件是垃圾邮件。

一种选择是通过 cron 作业发送电子邮件。在这种情况下,发送一封电子邮件需要多长时间并不重要,只要所有电子邮件最终都被发送即可。

Sending to all subscribers by specifying them in BCC shouold work faster. Though, while it might be a good option for some private environment, I would not suggest to do that in public web pages/systems, as many might consider such email being a spam.

One option would be to send emails via cron job. In that case, it doesn't really matter how much time it takes to send an email, as long as all emails are eventually sent.

无妨# 2024-10-26 13:40:27

由于您只是要求提供选项,因此这里有一些选项:

  • 分析您的代码,并了解其速度慢的原因。也许您可以解决一些效率问题。
  • 通常不建议依赖 mail() 函数,特别是因为存在 swiftmail 或 Zend_mail 等更好的替代方案。尽管这些对于小型邮件需求来说可能有点过分了
  • ,但它可能是服务器相关的问题吗?也许与您的服务器管理员联系。

Since you're simply asking for options, here are a few:

  • Profile your code, and see why its slow. Maybe you could iron out a few efficiency issues.
  • Relying on the mail() function is usually not advisable, especially since better alternatives like swiftmail or Zend_mail exist. Although these might be overkill for small mailing requirements
  • It could, possibly, be a server related issue? Maybe talk to your server administrator.
单调的奢华 2024-10-26 13:40:27

Cron Job 是更好的主意。我用过这个,它有效......
配置文件您的代码将帮助您找出问题。

Cron Job is better idea. I used this and it works...
Profile you code will help you to figure out the problem.

婴鹅 2024-10-26 13:40:27

我确实建议通过密件抄送发送邮件,因为这样会快得多。您的脚本只需与 SMTP 服务器建立一个连接,该服务器将为您完成其余的工作。

我还会看一下 PHPMailer 或 PEAR::Mail 等。
用于批量邮件的 mail() 方法的缺点是,它会为发送的每封电子邮件打开一个到 SMTP 服务器的新套接字。
一个好的邮件库将创建一个到 SMTP 服务器的套接字连接一次,然后发送所有电子邮件并在最后关闭它。

为了加快速度,您还可以查看您的 SMTP 服务器配置(如果可能)并尝试增加守护进程等。
您可能还需要考虑某些 SMTP 服务器具有可发送的最大数量。

I do recommend sending the mail via BCC because it will be a lot faster. Your script just has to make one connection to the SMTP server and this server will do the rest for you.

I would also take a look at for example PHPMailer or PEAR::Mail.
The bad thing about the mail() method for bulk mails is that it will open a new socket to a SMTP server for every email thats send.
A good mail library will create a socket connection to the SMTP server once and will then send all the emails and closes it at the end.

To speed it up a bit more you could also look at your SMTP server configuration (if possible) and try to increase the daemons etc.
You might also want to take in consideration that some SMTP servers have maximums you can send.

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