Send mail() using PHP on Mac OS X

Thanks to Benjamin Rojas, Andy Stratton, and a tip from Jasper, I was able to successfully send email from my home-brewed MAMP environment. Here’s the summary.

  1. Add the following to your /etc/postfix/sasl_passwd file:
(Of course, you don&#8217;t have to use GMail or port 587, but you get the idea.)</li> 

  * Configure postfix: 
        sudo postmap /etc/postfix/sasl_passwd

  * Backup and edit your postfix configuration: 
        sudo cp /etc/postfix/ /etc/postfix/
        sudo vim /etc/postfix/
    If you use TLS, then you will need to add the TLS settings but the other settings should already be there as a result of running the `postmap` command. You should have these options set in `/etc/postfix/`:
        mydomain_fallback = localhost
        mail_owner = _postfix
        setgid_group = _postdrop

  * Start postfix: 
        sudo postfix start
    If there are errors, you may need to edit your `/etc/postfix/` and restart postfix:
        sudo postfix reload

  * Send a test message: 
        date | mail -s test

  * Make postfix start automatically on boot by opening your `/System/Library/LaunchDaemons/org.postfix.master.plist` file and adding: 
    Add this at the bottom just before the closing `</dict> tag.`</li> 
      * Edit your `/etc/php.ini` file and configure the `sendmail_path` option: 
            sendmail_path = "sendmail -t -i"</ol> 
    You should now be able to send email using PHP&#8217;s <a href="" target="_blank"><code>mail()</code></a> function. If you continue to have issues, watch the contents of your postfix mail log:
        tail -f /var/log/mail.log
Written on April 19, 2013