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.
Michael berkowski
source share