Mountain Lion killed – or rather: disabled – sendmail by default. Big deal? well, if you need to send mail from PHP in your local development environment, you’ll need to perform these few steps to get it working again.
- To start postfix the first time, you’ll need to prepare the system a bit;
sudo mkdir -p /Library/Server/Mail/Data/spool
sudo /usr/sbin/postfix set-permissions
sudo /usr/sbin/postfix start
- Then you probably want postfix to be started on every boot;
Edit(sudo nano ….) and add
/System/Library/LaunchDaemons/org.postfix.master.plistto the propertylist, just before the last
- Test with Shell commandto test your systems ability to send mail and
whoami | mail -s test firstname.lastname@example.org
- Shell commandto test PHPs ability to do so.
whoami | php -r "mail('email@example.com', 'test', reset(file('php://stdin')));"
Please note: your mail may be regarded as spam since your sender-domain will undoubtedly not match your IP-address. Don’t hold me responsible. If you need to send a lot of mail this way, consider configuring postfix to use Authenticated SMTP and send the mail through your mail-providers SMTP server.
Also note; in some cases a reboot is needed between steps 2 and 3.
3 thoughts on “Sending mail from PHP with Mountain Lion”
Step 3) says “Reboot and test with” – but no reboot is required! :)
I thought that too, but on 2 of 8 computers I did this, I really had to. Perhaps I’ll change it to ‘Step 3, in case it’s needed; reboot’ :)
Only need to restart postfix ;)