是什么让 PHP 的 mail() 函数如此缓慢?

时间:2023-01-19
本文介绍了是什么让 PHP 的 mail() 函数如此缓慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的服务器上创建了一个包含对 mail() 调用的快速 PHP 脚本并开始测试它.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.

无法立即交付的潜在原因有很多.可能,您看到的延迟是接收服务器上的灰名单,这意味着接收邮件服务器拒绝接受消息,直到发送服务器(您的 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.

这篇关于是什么让 PHP 的 mail() 函数如此缓慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:如何允许远程访问我的 WAMP 服务器(用于移动设备 下一篇:如何根据用户所在的国家/地区显示不同的主页

相关文章

最新文章