問題描述
我在我的服務器上創(chuàng)建了一個包含對 mail() 調用的快速 PHP 腳本并開始測試它.html 頁面總是立即加載,所以我認為這意味著包含對 mail() 調用的 PHP 已完成執(zhí)行.但是,從 mail() 發(fā)送的電子郵件只會在通話后每 10-20 分鐘收到一次.為什么延遲?mail() 是否觸發(fā)外部程序?(如果相關,電子郵件將發(fā)送到 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.
無法立即交付的潛在原因有很多.可能,您看到的延遲是接收服務器上的灰名單,這意味著接收郵件服務器拒絕接受消息,直到發(fā)送服務器(您的 PHP 腳本將其交給)嘗試重新發(fā)送幾次.表現良好的 MTA 會重試失敗的發(fā)送嘗試,但垃圾郵件服務器通常不會,這使得這是減少垃圾郵件的一種簡單而有效的方法.
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 服務器上等待發(fā)送的長消息隊列一樣簡單,而您的消息正在排隊等候.(不過,真正列入灰名單的可能性更大)
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)
最重要的是要記住,電子郵件不是即時的,因此永遠不能保證是即時的.在過去十年左右的時間里,我們基本上已經習慣了電子郵件的快速發(fā)送,但您永遠無法保證快速發(fā)送.
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.
這篇關于是什么讓 PHP 的 mail() 函數如此緩慢?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!