Configure Postfix in OS X MAMP to Use PHP “mail” Function

2015-03-07 OS X

Sooner or later you will reach the point where your application will have to send e-mails from your local environment. I will show you how to properly set MAMP and Postfix in OS X to be able to push messages using PHP’s mail function or using terminal command.


One of the further steps will require to provide credentials to your real and existing mailbox. For safety reasons, instead of providing details to you use daily, create new one with a distinguishable name like mailing@your_domain.tld.

  1. OS X
  2. MAMP PRO with at least one working virtual host (to test PHP mail function)
  3. Existing mailbox from your current hosting provider with details about SMTP server:
    1. SMTP address
    2. port
    3. information whether TLS is used or not


Open MAMP PRO, turn off the server if it’s running right now and switch to the Postfix tab. Fill everything as you see on the screen below.

OS X Postfix

Now edit php.ini. Switch back to the Hosts tab and see which PHP version your virtual host is using. Remember the number and now go to:


Open php.ini and search for a phrase


Change the port number (smtp_port) to the one that is used by your hosting. In my case I had to set it to 587.

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 587

Leave SMTP as it is.

Go to Terminal because now most of the time we’ll spend with command line (but don’t be scared). I can assure you, that the whole workflow is not so difficult. Open

sudo mcedit /etc/postfix/sasl_MAMP_passwd

and put credentials using following syntax:

<smtp_address>:<port_number> <sender_email_address>:<sender_email_password>

something similar to:

Now, backup existing Postfix configuration file

sudo cp /etc/postfix/ /etc/postfix/


sudo mcedit /etc/postfix/

and scroll down to the MAMP section.

Variable myorigin should be exactly the same as the domain of the sender e-mail address that you provided in sasl_MAMP_passwd file. Variable relayhost should match SMTP server and port from the same file as well.

### MAMP Postfix Configuration - Start ###

myorigin =
myhostname = mailer.$myorigin
smtpd_sender_restrictions = permit_inet_interfaces

# smart host
relayhost =
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_MAMP_passwd
smtp_sasl_security_options = noanonymous

### MAMP Postfix Configuration - End ###
# DONT REMOVE: MAMP PRO template compatibility version: 1

Right now we have to reload configuration and (re)generate DB file:

sudo postmap hash:/etc/postfix/sasl_MAMP_passwd


sudo postfix start
sudo postfix reload


Now restart MAMP and create a PHP script with below content. This trivial code will try to send an e-mail.

mail('', 'Hello world', 'Testing Postfix');

Save the file somewhere under your virtual host as test.php and open it in any browser.


Now switch back to terminal and type

date | mail -s test

Now check your mail. If everything is done properly, you should receive two e-mails. One called “Hello world” and second called “test” that contains current date.

If you still have problems then watch mail logs by typing

tail -f /var/log/mail.log

You’re done.

See how flexible it is. Obviously the PHP mail function will work only when the server is running but using mail directly in terminal will work all the time. Thanks to that, you can create a bash script (triggered by the Cron) that can notify you for example when your backup is ready.