如何使用php mail()函数而不破坏服务器? [英] How to use php mail() function without crashing the server?

查看:174
本文介绍了如何使用php mail()函数而不破坏服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想发送一些使用php的批量电子邮件。过去我已经做了一个foreach循环,我使用php mail()函数。但是,当有很多电子邮件发送出去时,通常会备份并崩溃服务器。

解决方案

不要使用 mail()大容量电子邮件发送功能。 (我认为这在手册中甚至说明了)。该函数打开一个新的smtp连接每个邮件,这是非常无效的。更好地使用SMTP客户端,可以为所有电子邮件重复使用相同的连接。



您将在google上找到很多图书馆。对于我来说,第一个结果是一个整体的MTA,这可能是有趣的,因为你可以做很多更准确的统计数据。如果你不喜欢试验,可以随时使用PEAR课程,邮件是您需要的。



编辑:只需检查手册。有一个大量电子邮件的说明:


值得注意的是,mail()函数不适合较大的
一个循环中的电子邮件量。这个
函数打开并关闭每个电子邮件的SMTP
套接字,这不是
非常有效。



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



I want to send out some batch e-mails using php. I have done so in the past with a foreach loop within which I use the php mail() function. However, when there are a lot of e-mails to send out, this often gets backed up and crashes the server. How can I do this without overwhelming the system?

解决方案

Don't use the mail() function for mass e-mail sending. (I think it's even stated in the manual.) The function opens a new smtp connection per mail, which is highly ineffective. Better use an SMTP client, which can reuse the same connection for all your emails.

You'll find lots of libraries on google. The first result for me is a whole MTA, which might be interesting, because you can do much more accurate stats with that. If you're not feeling like experimenting, you can always use PEAR classes, Mail is what you need.

Edit: Just checked the manual. There's a note on mass e-mailing:

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.

这篇关于如何使用php mail()函数而不破坏服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆