PHP, Mail() and Mountain Lion

As I was working on implementing email (sendmail) in symfony2, I stumbled upon an annoying issue with emails not being sent on my local machine using Mail() with MAMP. I didn't have this issue prior to upgrading to Mac OS X Mountain Lion so if you're on a version of OSX older than Mountain Lion, you might be okay. I should probably say that I'm not by any means an expert on the subject. This solution came upon trial and error so hopefully this will help you save sometime if you're dealing with this issue. It seems to be a common issue since Mountain Lion came out, and that's why I decided to write about it.

Mountain Lion uses sendmail as an alias for postfix (not sure why) so you need to configure postfix instead of sendmail. You'll need to alter 3 files in your local machine to enable mailserver and postfix. You can follow this step-by-step process here. The files are:

  1. /etc/hostconfig
  2. /etc/postfix/
  3. php.ini (since I'm using MAMP, this is located here /Applications/MAMP/conf/php5.4.4/php.ini)

I followed the step-by-step tutorial above and I couldn't still send email with Mail() successfully. After inspecting the mail log (tail -f /var/log/mail.log), I was able to see that postfix wasn't working and I was getting an error mainly because I didn't have the directories postfix was looking for. You can create the directories by running this command at your terminal.

sudo mkdir -p /Library/Server/Mail/Data/spool
sudo /usr/sbin/postfix set-permissions
sudo /usr/sbin/postfix start

You may (or may not) see some errors after running these commands but postfix should be working now. I hope this saves you hours of work!

DisclaimerIf there is ever any doubt, the views expressed here have nothing to do with those of my employer. read more

Even though I work for Target Corp, the views expressed here are my personal views and do not necessarily reflect the thoughts, opinions, intentions, plans or strategies of my employer.

And some legalalize:

All of my online communications are provided “as is” with no warranties or indemnities of any kind, and do not confer any rights. My employer is not responsible for the accuracy of any of my online communications.

You should know that I have no ability to bind my employer to any legal obligations. By way of example, I have no authority to grant or confer any right or license, either express, implied or by estoppel, under any patent, copyright, trade secret or other rights of my employer. If you would like a license to any intellectual property or other rights of my employer, you must enter into a written contract directly with it.

comments powered by Disqus