Sending mail from PHP with Mountain Lion

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.

  1. To start postfix the first time, you’ll need to prepare the system a bit;
    Shell commandsudo mkdir -p /Library/Server/Mail/Data/spool
    sudo /usr/sbin/postfix set-permissions
    sudo /usr/sbin/postfix start
  2. Then you probably want postfix to be started on every boot;
    Edit
    /System/Library/LaunchDaemons/org.postfix.master.plist
    (sudo nano ….) and add
    <key>RunAtLoad</key>
    <true/>
    to the propertylist, just before the last
    </dict>
  3. Test with
    Shell commandwhoami | mail -s test youremailaddress@yourdomain.com
    to test your systems ability to send mail and
  4. Shell commandwhoami | php -r "mail('youremailaddress@yourdomain.com', 'test', reset(file('php://stdin')));"
    to test PHPs ability to do so.

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.

Author: Remon Pel

WebDeveloper though not WebDesigner

3 thoughts on “Sending mail from PHP with Mountain Lion”

Leave a Reply

Your email address will not be published. Required fields are marked *