Is there a limit when using php mail function?

一个人想着一个人 提交于 2019-11-27 15:40:19

Please be aware of this note from the mail documentation:

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 the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.

No limit to the emails number, but there is the time limit of the PHP script. See the max_execution_time set in your php.ini, typically it's 20 or 30 seconds. If you don't know that, use phpinfo() to find it out.

Moreover, you should take some steps to prevent users from getting too much emails. You should mark them as sent, so they don't receive double posts if you accidentally start the script twice.

Other than that, you should note that php's mail function is inherently not optimized at all. You could try some libraries, like phpmimemessage or any other, which will allow you do to some caching, for example, among many other features.

You should build a queue of emails sent/failed, so you can try to resend failed attempts and avoid re-sending emails if something should go wrong.

Do not create a loop that tries to send 10k emails via mail()

Also, the most likely limit you'll hit will be that of the mail server of your ISP or host.

warren

You may also want to look at setting up a "real" mailing list tool, such as mailman, or at least using alias groups (if possible).

Also, see the related questions on serverfault: https://serverfault.com/questions/67154/sending-an-email-to-about-10k-users-not-spam, where PHPlist is mentioned, along with others. And here - https://serverfault.com/questions/68357/whats-the-best-way-to-send-bulk-email.

Peter Parker

You can use pear::Mail_Queue http://pear.php.net/package/Mail_Queue/

It will really do a good job.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!