PHP's mail() function flaky as heck

I’m wondering why PHP’s mail() function returns true and no email arrives?

PS. I’m not even sending it to some outside domain. I’m sending it to my own email address that is registered with my domain at Dreamhost.

Did Dreamhost accumulate so many scam accounts that blast out spam that they have to resort to lying for the return value of the mail() function by silently absorbing and discarding all messages? So annoying! No consistency at all. Can I find a reliable hosting provider? (Rhetotical question.)

PHP’s mail() return true when “the mail was successfully accepted for delivery”, not when successfully delivered (this is generally unknowable for SMTP). So the true value just means the local webhost has accepted the email and queued it up for delivery. Later, the webhost sends the email to a central relay server (e.g., which then sends it to the destination.

There’s a trouble-shooting article, which suggest checking for local bounces:

Thanks. There’s indeed a bunch of messages in /home/username/Maildir/new.

Like this one from today: host[xx.xx.xx.220] said: 550
5.7.1 Unauthenticated email is not accepted due to domain’s DMARC policy
(in reply to end of DATA command)

but then when I login to CP and see this. The SPF is set up automatically for, is it not:

So why is my mail being rejected?

I don’t see the SPF record in the screenshot. It would look something like this:

TXT	 v=spf1 mx -all

Is that a vanilla mail account on the DreamHost box or was it moved here from elsewhere?

Thanks. I was wondering, is there a way to send an email via PHP to the email account hosted at the same domain at dreamhost without whitelisting all outbound mail from and

It’s an email account I created via dreamhost CP.

I am just looking for a way to send email to that (self) email account from my PHP script that runs on the dreamhost servers without whitelisting whole two domains: and

I think there would be two options:

Use mail() without setting From address

I’m assuming you’re setting the From address to your own domain with mail(), but if you don’t set it then mail() defaults to using the webhost user account as the From address (e.g. The default email From address can’t violate DMARC policy (because they have none). Of course, without DMARC the emails are more likely to be caught by spam filters.

Send email via SMTP, rather then local mail

With SMTP, you can send email with any email service (Gmail, Mailgun, DH, etc). If you use DH SMTP service, then the emails will be DKIM signed and can pass DMARC even with a very narrow SPF record (possibly even -all). DH has an article on sending SMTP with PHP::

Oh wow. That is awsome. Removing "From: " field from the PHP mail() headers solved the problem. No need to whitelist all the email addresses hosted on Dreamhost via SPF!

And yes, of course it’s just a local notification for myself. In other words such email doesn’t go anywhere outside of the dreamhost servers. My only requirement is that it is delivered reliably into my inbox!

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.