Setting up DNS with mail on Dreamhost; getting PHP to find the right mail server

  • Posted January 2, 2014

I’ve got a droplet running a site (let’s call it For a variety of historical reasons, the site’s domain is registered at Dreamhost, which is currently providing the domain’s DNS and mail service. This is working fine EXCEPT that the site (based on Drupal 7) is not able to send mail to an address at – when I track /var/log/maillog, Postfix reports that the attempt to send fails because of an unknown user (yes, the user really exists in the Dreamhost mail system); this happens both when Drupal (php, really) tries to send mail and when I manually send mail from the shell via mailx. Outgoing mail from the site is in fact working, by the way; I can send to addresses other than via both php and mailx. Finally, I’m not running a DNS server as part of the droplet.


(1) How do I get the site to understand where its mail server is? I’d like to leave the mail service at Dreamhost for now, but I’m open to moving the DNS service to DigitalOcean if that makes things easy/possible.

(2) Once mail is working, I’ll want to set up SPF records for the domain. I guess it’ll be obvious where/how to do that, but that will be an issue down the road.



Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This is one reason I don’t name my droplets as the parent domain (e.g. don’t name your droplet ‘’). The default postfix configuration assumes that it should handle email addressed to the host it is on. Give your droplet a subdomain name (e.g. I use ' - ‘do’ to indicate a DO host (I do have machines in the same domain on on other services), ‘s’ to indicate a server, and N is a server number. So my first DO server would be named Come up with your own naming convention - I use tolkien names on my home machines.). Then CNAME service domain names (e.g.,, to the appropriate host name, and put the appropriate A record on the domain root if, for example, you want your web site accessed without the www. If the droplet’s name is, e.g., then the postfix server running on it will assume that it handle emails for, not for

OK, I think I’ve got this fixed. First, I’m really running postfix, the default mail agent for CentOS 6.4, which the site is running. Second, what I’m apparently trying to do is to set up postfix as a “null client”, which sends but does not receive mail. The definitive writeup on this is at , but was a bit more direct: /etc/postfix/ needs to be edited to specify inet_interfaces = loopback-only and mydestination = Once I made those changes and restarted postfix, things worked appropriately: mail still worked, and mail to used the Dreamhost servers as specified in the domain’s MX records. So far, anyway… <br> <br>

Looks interesting; thanks! But I think my real problem lies with the site not having a correct notion of where its MX servers are. msmtp looks like a replacement for sendmail, but I’m not sure that it would behave any differently regarding figuring out which server to talk to.

Have you seen <a href=“”>How To Use Gmail or Yahoo with PHP mail() Function</a>? <br> <br>Postfix may also be more than you need. Why not go with a lightweight alternative, like <a href=“”>Exim</a>?

@Pablo: I don’t think so; I can send from outside domains into addresses at, and everything works fine. I’ll hypothesize that the responsible mail system (postfix?) is noting that the message is going from one address at to another, and so doesn’t bother doing a DNS call to figure out where the appropriate server is. But that puts me way out on the edge of my competence in understanding this stuff…

<b>"Outgoing mail from the site is in fact working, by the way; I can send to addresses other than via both php and mailx.</b> <br> <br>Wouldn’t that suggest that the problem lies with Dreamhost and <i>not</i> the DigitalOcean droplet? Perhaps you need to add an SPF record, at Dreamhost, to authorize the droplet to send mail on behalf of “”

Yes, I think you’re exactly right – the DO host incorrectly thinks that it’s handling mail for (even though doing “dig mx” comes up with the Dreamhost servers). So: how do I convince the DO host that Dreamhost should be handling the domain’s mail services?

Is the name of your DO server Are you using the standard install for whatever email server is running on your DO site. Does that mail server therefore think that It is handling email for the domain I suspect that you’re not talking to the DreamHost email servers at all, because the email server on the DO host thinks it is handling email for, and tries to deliver the email locally. <br>