What makes the PHP mail () function so slow?

I made a quick PHP script on my server containing a mail () call and started testing it. The html page always loads instantly, so I guess that means the PHP containing the mail () call is complete. However, letters sent from mail () are only accepted every 10-20 minutes after the call. Why is the delay? Does mail () run external programs? (emails are sent to the gmail email account if necessary)

+7
php email networking gmail
source share
2 answers

The behavior you see has nothing to do with the PHP mail() function. Instead, it is an SMTP mail server from which PHP sends a message, which takes time for delivery. This service is known as a mail transport agent or MTA .

There are many potential reasons why it will not be delivered immediately. Perhaps the delay you see is greylisting on the receiving server, which means that the receiving mail server refuses to receive the message before sending the server (which your PHP script transmitted), tries to send it again several times. A well-managed MTA will retry unsuccessful submission attempts, but spam servers often do not, making this a simple but effective method to reduce spam.

It can even be as simple as a long message queue on an SMTP server waiting to be sent, according to which you are waiting for a queue. (Indeed, greylisting is more likely, though)

The most important thing to remember is that email is not designed to be instantaneous and therefore is never guaranteed to be instantaneous. Over the last decade or so, weโ€™ve been accustomed by and large to send emails very quickly, but you can never promise fast delivery.

+12
source share

As @Michael Berkowski said, this is not the mail () function itself. mail () works by calling your systems embedded in the SMTP courier software. Then it automatically negotiates the conversation with the receiving system, performing the necessary DNS lookups to find the correct mail server. Then this server takes your message, checks your system through gray lists and reverse DNS queries, scans them and runs them against its own protection against spam and viruses, and then finally delivers. In addition, many mail servers delay unknown sending servers to prevent the distribution of DOS mail and fishermen.

+5
source share

All Articles