Results 1 to 2 of 2

Thread: How to prevent PHP mail() messages from being caught in spam?

  1. #1
    Administrator Kavoir's Avatar
    Join Date
    Dec 2009

    How to prevent PHP mail() messages from being caught in spam?

    I have set up a variety of domains to use PHP mail() function to send email messages to a diversity of recipients, such as me myself and my customers, etc. For long, the problem had haunted me that messages were irregularly caught and dropped in the spam folder by email services such as Gmail.

    After some investigation and testing, I finally am able to pull this thing off once and for all - now none of my messages sent from PHP mail() function will ever get in the spam folder of the recipient's inbox.

    The trick is, you have to ALWAYS send the email from the domain name, that is, to set the From header as "From: John Doe <>" when you are performing the mail() function on

    Never use email address from other domains or 3rd party free email services such as or anything in the From header when you are sending the message via mail() from your own domain. It will most certainly be identified as spam, especially when you have no SPF record or DKIM signed.

    While this one trick should make everything fine, you can also consolidate your mail() by setting an SPF record and enable DKIM.

    Most modern hosts seem to have taken care of the SPF automatically after you have added the domain in cPanel. DKIM is also readily deploy-able for your domains in cPanel. DreamHost is the only host I know who goes the extra mile by NOT allowing mail() to send any messages with a From header that's different from the domain. You have to first get everything right or the messages won't be delivered at all.
    The road goes ever on and on.

  2. #2
    Junior Member Princessly's Avatar
    Join Date
    Oct 2012
    I would do these to prevent PHP mail() messages from being dumped in the spam:

    1. Set an SPF
    2. Enable DKIM
    3. Make sure messages are "From: " the actual domain that is sending them
    4. Most importantly, make sure "Return-Path" is the same domain as that of "From" in the message headers - this would get rid of the annoying 'via' field in Gmail.
    Live in the fairy tale, Princessly, the valiant store.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts