Blue Static

Getting PHP mail() to Work on OS X Tiger

Posted on July 13, 2007 at 04:43 UTC, filed under the category Uncategorized.

I recently (as in this week) got my brand new MacBook Pro. It’s shiny and I love it and for the past few days I’ve been transitioning my life from desktop to laptop. One of the things I had to do was to get PHP installed and working, which as usual, was straight forward. However, on Mac OS X, I couldn’t figure out why PHP wasn’t properly sending out email. The answer lies in the fact that, by default, Mac OS X does not start Postfix (which is what is used to send email). I searched the web for numerous tutorials on how to get this to work, but all of it conflicted. Ultimately I just read the man pages on launchd (the thing that makes OS X start) to get it to work after comparing my laptop’s configuration to my desktop’s.

So this will get the Mac OS X mail server working on 10.4.10 (and most likely all of 10.4.x):

Edit, as root, /etc/hostconfig and add this line (presuming there are no other lines for “MAILSERVER”, and if there are, simply change it to be this):

MAILSERVER=-AUTOMATIC-

And then run this command in the Terminal:

sudo launchctl load /System/Library/LaunchDaemons/org.postfix.master.plist

Next time you reboot, Mac OS X’s mail server will be working hunky-dory. Note: this will not create a persistent SMTP server, but instead will start when an email is sent and then will automatically close when it’s done (so Postfix will not run in the background when you don’t need it).