PHP的mail()函数如此之慢? [英] What makes PHP's mail() function so slow?

查看:110
本文介绍了PHP的mail()函数如此之慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在包含对mail()的调用的服务器上创建了一个快速PHP脚本,并开始测试它。 html页面总是立即加载,所以我认为这意味着包含对mail()的调用的PHP完成执行。但是,从邮件()发送的电子邮件只会在呼叫后每10-20分钟收到一次。为什么延迟? mail()是否触发外部程序? (如果相关的话,这些电子邮件将被发送到一个gmail电子邮件账户)

您看到的行为与无关PHP的 mail()函数。相反,它是PHP将邮件传递给它的SMTP邮件服务器,这需要时间来交付。该服务被称为邮件传输代理或MTA



有很多潜在的原因不会立即交付。可能的是,您看到的延迟是在接收服务器上灰名单,这意味着接收邮件服务器拒绝直到发送服务器(你的PHP脚本交给它)尝试几次重发它。行为良好的MTA会重试失败的发送尝试,但垃圾邮件服务器通常不会,因此这是一种简单而有效的方法来减少垃圾邮件。

它甚至可以是很简单,就像在等待发送的SMTP服务器上的一长串消息一样,因此您的排队正在等待。 (真的很可能是灰名单)



最重要的是要记住,电子邮件是 not 旨在是瞬间的,因此不能保证是瞬间。在过去的十年左右,我们已经习惯了大部分电子邮件的发送速度非常快,但您永远不能承诺快速交付。


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)

解决方案

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.

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.

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()函数如此之慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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