Emails sent using the PHP mail() function are marked as spam


I believed I have set up everything correctly, but it seems I am missing something.

  1. I set up my DNS, MX server and SPF this way:

<img alt="Alt text" src="">

If I understand the SPF syntax well, it seems that emails sent from and my MX servers should pass.

  1. But all emails sent using the PHP mail() function are marked as spam. This is the first dmarc report from Gmail I have received - it seems that the email did not pass the SPF check.

<img alt="Alt text" src="">

  1. On the other hand, when I use the "show original" menu in Gmail, it says SPF: PASS.

<img alt="Alt text" src="">

So, I don't understand two things:

  1. Is there something wrong with my SPF settings?
  2. Why the messages end in the SPAM folder when I have set up SPF, DKIM and DMARC?


1 Reply


This can happen for many reasons using the PHP mail() function. It's also a bit hard to narrow down without some further information.

What mail providers are marking these emails as spam?

Are there any mail providers that don't mark it as spam?

Do you have reverse records for all of the locations you're mailing from?

If you're looking to validate your records MX toolbox has some tools that should help you do this.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct