BCC 发送 PHP mail() 到邮件列表的方式与 TO 不同吗?
我正在改进 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
以密件抄送方式发送给所有人将会更快很多。该代码将执行得更快,并且
mail()
将仅执行一次。这是快速修复方法,但正如前面提到的,大型密件抄送列表是通往垃圾邮件文件夹的安全途径。然而,使用
mail()
也肯定会成为垃圾邮件的目的地。如果您想真正改进它,请使用 SourceForge 的 PHPMailer 并通过 SMTP 发送(减少垃圾邮件命中)在 X 封邮件中使用 cron 一次。
PHP 文档指出:
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:
通过在密件抄送中指定所有订阅者来发送给他们应该会更快。不过,虽然对于某些私人环境来说这可能是一个不错的选择,但我不建议在公共网页/系统中这样做,因为许多人可能会认为此类电子邮件是垃圾邮件。
一种选择是通过 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.
由于您只是要求提供选项,因此这里有一些选项:
mail()
函数,特别是因为存在 swiftmail 或 Zend_mail 等更好的替代方案。尽管这些对于小型邮件需求来说可能有点过分了Since you're simply asking for options, here are a few:
mail()
function is usually not advisable, especially since better alternatives like swiftmail or Zend_mail exist. Although these might be overkill for small mailing requirementsCron Job 是更好的主意。我用过这个,它有效......
配置文件您的代码将帮助您找出问题。
Cron Job is better idea. I used this and it works...
Profile you code will help you to figure out the problem.
我确实建议通过密件抄送发送邮件,因为这样会快得多。您的脚本只需与 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.