是什么让 PHP 的 mail() 函数这么慢?
我在我的服务器上创建了一个快速的 PHP 脚本,其中包含对 mail() 的调用并开始测试它.html 页面总是立即加载,所以我认为这意味着包含对 mail() 的调用的 PHP 已完成执行.但是,从 mail() 发送的电子邮件只会在通话后每 10-20 分钟收到一次.为什么延迟?mail() 会触发外部程序吗?(如果相关,电子邮件将发送到 gmail 电子邮件帐户)
I made a quick PHP script on my server containing a call to mail() and started testing it. The html page always loads instantly, so I assume that means the PHP containing the call to mail() is finished executing. However, the emails sent from mail() are only ever being received every 10-20 minutes after the call. Why the delay? Does mail() trigger external programs? (the emails are being sent to a gmail email account if that's relevant)
推荐答案
您看到的行为与 PHP 的 mail()
函数无关.相反,PHP 将消息交给 SMTP 邮件服务器,这需要时间来传递.该服务被称为邮件传输代理或MTA.
The behavior you are seeing has nothing to do with PHP's mail()
function. Instead, it is the SMTP mail server which PHP hands off the message to, which is taking time to deliver. That service is known as a mail transport agent, or MTA.
无法立即交付的潜在原因有很多.您看到的延迟可能是接收服务器上的 greylisting,这意味着接收邮件服务器拒绝接受该消息,直到发送服务器(您的 PHP 脚本将其交给该服务器)尝试几次重新发送它.表现良好的 MTA 会重试失败的发送尝试,但垃圾邮件服务器通常不会,因此这是一种简单但有效的减少垃圾邮件的方法.
There are lots of potential reasons it won't be delivered immediately. Possibly, the delay you see is greylisting on the receiving server, meaning that the receiving mail server refuses to accept the message until the sending server (which your PHP script handed it to) tries a few times to resend it. Well-behaved MTA's will retry failed send attempts, but spam servers often don't, making this a simple but effective method for cutting down spam.
它甚至可以像 SMTP 服务器上等待发送的一长串消息一样简单,而您的消息正在排队等待.(实际上,灰名单更有可能)
It could even be as simple as a long queue of messages on the SMTP server waiting to be sent, whereby yours are waiting in line. (Really greylisting is more probable though)
最重要的是要记住,电子邮件并非旨在即时发送,因此永远不能保证是即时发送的.在过去十年左右的时间里,我们大体上已经习惯了电子邮件的快速送达,但您永远不能保证快速送达.
Most important to remember though is that email is not intended to be instantaneous and therefore never guaranteed to be instantaneous. In the past decade or so we've gotten accustomed by and large to email being delivered really quickly, but you can never promise quick delivery.
相关文章