Question

I have 2 mail functions, like this:

mail( $from, '', 'mail1', $headers );
mail( $from, '', 'mail2', $headers );

If I test it with my own email address in the $from, sometimes I receive mail1 first and sometimes I receive mail2 first. I want to always receive mail1 first. I tried putting a usleep in between the 2 mail functions, but it didn't work.

Was it helpful?

Solution

You can't. The order in which you receive mails isn't up to you. Mail may take many paths, and be delayed at any SMTP server along the way.

The best you could do would be to forge the date headers, making one e-mail appear to be sent a minute earlier than the other. Most mail clients will order them by date sent. Be cautious of this though, and don't go too far with it. Spammers use the same tactics, and e-mail providers know this.

OTHER TIPS

After your mail function executes, the actual delivery of the email is left to Mailservers. That is, you cannot control which comes first to the inbox after releasing control of the email from your server/PHP code.

Read up on the Mail Transfer Agents and how they operate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top