Fix PHP’s mail() function after latest OS X (Leopard) update.

Jaspert Tandy just saved my life. Okay, maybe not, but he sure did make my day this morning. Why? He has a great post that gives you some simple steps to fix problems with sendmail/postfix on OS X (Leopard).

The problem:

I updated OS X and all of a sudden my local PHP installation isn’t sending mail. No errors, no warnings. Everything functions correctly but the mail never actually makes it to the inbox.

The solution:

Jasper outlines the the solution in his great post. I’m going to mark the steps I took after reading his post, but by all means give the man a thank you, a beer, a hug, or something!

Open terminal, you’ll need it:

  1. Turn on the mail server your hostconfig file:
    Run sudo nano -w /etc/hostconfig in Terminal. Look for the line starting MAILSERVER=, if you don’t see it, add it and make sure it reads:


    Terminal - Edit hostconfig

  2. Edit your posfix configuration file:
    First, I normally backup a configuration file before messing with it, since I’m no Terminal guru. If you want to take this precaution too, run this command in Terminal: sudo cp /etc/postfix/ /etc/postfix/

    Now, run sudo nano -w /etc/postfix/ and find the lines defining the myhostname variable. Remove the leading number/pound sign (#) to uncomment the declaration and set it’s value to something you own, or something you can recognize.

    Terminal - Edit postfix config

    Note that if you set this to something obscure like I have, your email messages without from: headers will send from your Apache user (mine’s _www) at this domain. For instance, my emails send from _www@theandystratton.desktop.local. These tend to be blocked by Gmail’s spam filter (and probably most spam filters).

  3. Edit your php.ini just in case

    Open your php.ini file and uncomment the sendmail_path variable by deleting the leading semicolon (;).

    Set its value to sendmail -t -i so that line reads:

    sendmail_path = "sendmail -t -i"

    Restart Apache so the setting applies to you PHP install.

  4. Test your mail() script.

    Run a sample PHP script to see if you’re able to send mail. If you’d like to see what’s going on or get a confirmation from your log files that the email is working, check out Jasper’s tip using tail to show what’s happening with sendmail/postfix in Terminal in real time.

Did it work for you? Send Jasper some love and thank him. This is an aggregation of his solution and a journal of what helped me, in hopes that his solution can reach more people.

Thanks again, Jasper.


  1. Pooh says…

    Thanks a lot.

  2. andy says…

    No worries, again, this solution was adapted from Jasper Tandy’s, but I’m glad my aggregation of it helped you out, that was the goal!

  3. Rasmus L. Knabe says…

    Hi. apparently this doesn’t work for me.. I have previeusly set op me iMac send mail via PHP, but this stopped to work after i installed SN. I have now added the line:

    sendmail_path = “sendmail -t -i”

    to my php.ini.default file (I have no filed just called php.ini?).

  4. andy says…

    What is “SN”? Do you mean you upgraded to Snow Leopard? This post is in reference to the last update to Leopard. Snow Leopard would be an upgrade.

    Also, if you run <?php phpinfo(); ?> you should be able to see the path to the loaded configuration (php.ini) file on your system.

  5. Rasmus L. Knabe says…

    SN is Snow leopard yes, and your right about the upgrade/update πŸ™‚ (Not the server edition).

    The directory for my php.ini files is in /etc Acroding to – But the folder only contains php.ini.default (Wich is the file i have already edited).

  6. andy says…

    I’d run the following in terminal:

    sudo cp /etc/php.ini.default /etc/php.ini

    Then restart Apache. What’s probably happening is PHP is loading with its default compiled settings because it’s not finding php.ini, I don’t think it will pick up the settings in php.ini.default –

  7. Rasmus L. Knabe says…

    Sorry my bad.. it works just fine, but i forgot to forward port 25 from my router… Thanks for a great tutorial.. πŸ™‚

  8. andy says…

    Ha, no worries, glad you’re up and running!

  9. Rasmus L. Knabe says…

    By the way.. Do you have any idea if this guide allso aplys to OS X Leopard Server (It wont work there iegther :()

  10. Seth says…

    I’ve done this, but the e-mails aren’t going through.

    To make sure the problem isn’t PHP, I put the mail() in an if statement, and it passes.
    No errors appear in mail.log


  11. andy says…

    Not quite sure. This was mainly a re-post and modification of another post’s steps to fixing the issue. Are you on Leopard or Snow Leopard?

  12. Masuka says…

    Reallt Thanks… It work beatifully…..

  13. andy says…

    Of course! Be sure the thank @jaspertandy

  14. ZoRdAK says…

    Before reading this article, I tried many things and spent a lot of time on postfix/sendmail…

    But in 30second (time to read your article :p ) I success !!!

    Thank you a lot πŸ˜‰

  15. Laith says…

    HELP!!! i keep getting connection refused when I check the

    tail -f /var/log/mail.log

    and I see “_www”

    what do I do?

    my form is a simple form generated by

  16. andy says…

    _www is probably the user account of your local Apache server/PHP script attempting to send mail. I’m honestly far from a sysadmin and can’t support this. I wish I could, I mainly posted this as what I ended up doing based on some other posts I found, and what worked for me.

  17. Laith says…

    Do you know how i can change my user account of the local Apache server/PHP and or should i change this?

  18. Sendmail / Postfix broken since installing FiOS : Apache and PHP says…

    […] I’ve had issues before with my jury rigged Macports-powered MAMP setup. The biggest time suck has been postfix/sendmail […]

  19. Klederson says…

    Dude tks a lot i hate sendmail at Mac OS and never remember how to config it.

  20. Alberto says…

    Can you make a guide for snow leopard? i have the same problem the i can’t solve

  21. nicolas says…

    Can’t say more than thanks a lot !!!

  22. Phil says…

    Awesome! Thanks for the tips! Works perfectly ^_^

  23. mike says…

    For those of you still having problems, this seems to have worked for me (trying to send mail through my isp):

    add the following to (found in /etc/postfix)

    mydomain = yyy.zzz
    myorigin = $mydomain
    relayhost = xxx.yyy.zzz

    yyy is your internet service provider (comcast, att, whatever)
    zzz is the top level domain (net or com, most likely)
    xxx is the outgoing mail server (mail or smtp)


    If you aren’t using your isp’s servers, nevermind. My isp seems to “trust” valid user accounts inside it’s network; don’t know if that’s the norm.

    OS X 10.6.4 PHP 5.3.3

  24. Luc Wollants says…


    Many thanks for the good setup guide.

    To remove _www you need to modify your Apache configuration file and replace the User and Group values.

    You can find these steps on my personal blog which I use for personal reference:


  25. Mac OSX Labs says…

    Mac OSX Labs…

    What is d good about Mac besides the fact that hackers are focusing on PC\’s?…

  26. Configuring Postfix On Mac OS X 10.6 (or how to get sendmail/PHP mail() working) | says…

    […] Fix PHP’s mail() function after latest OS X (Leopard) update […]

  27. Bill says…

    I have a RapidWeaver site that has a contact page. It uses PHP. When I was running this on a OS X 10.3 server all was fine. Now it is on a OS X 10.6 server and it looks like it sends the message but nothing ever arrives. I have tried the fixes listed here but it still does not work.

  28. regesh says…

    Thanks a lot! finally i found solution! Thanks one more time!

  29. gabriel says…

    This is awesome thank you very much, i really enjoyed this article – a great programming lesson, now my XAMPP local server itΒ΄s sending and receiving email data, a must do for testing a buddyPress environment and learned a little more of command line in terminal and GNU nano 2.0.6 text editor, beautiful! πŸ˜€

  30. all says…

    Hey, after input sudo nano -w /etc/hostconfig command i found this ‘ # This file is going away ‘ in my terminal, what does it means?

  31. Wanda Chirnside says…

    I am stuck at point no. 1.

    I can’t seem to add MAILSERVER to the list in the terminal. I believe that I have change the php,ini file and default php.ini file and understand how to restart Apache. I just don’t know how to enable PostFix or whatever mail server I have – Mac OS X 10.5.8. Any help would be appreciated.

  32. andy says…

    I’m not sure what the “this file is going away” is. May want to consult nano’s docs.

  33. andy says…

    @Wanda this post is nearly two years old, so I’m sorry I’m really hazy on the solutions even I used to do this. This was a few weeks of painful clamoring around for me, as I’m not that skilled in sysadmin on any platform… I’m sorry I can’t be of more help!

  34. wee says…

    i have a similar problem with Mac OS 10.6.4
    mailq produces
    EFC65C06E7A 576 Tue Jul 26 17:13:15 _www@local.local
    (mail transport unavailable).

    my /var/log/mail.log says:
    warning: connect to transport smtp: Connection refused
    55A41C07A25: from=, size=583, nrcpt=1 (queue active)
    Jul 26 18:28:21 zhiwan-Gohs-iMac-2 postfix/error[963]: 5477DC07A24: to=, relay=none, delay=2454, delays=2454/0.02/0/0.01, dsn=4.3.0, status=deferred (mail transport unavailable)
    Jul 26 18:28:21 zhiwan-Gohs-iMac-2 postfix/error[964]: 55A41C07A25: to=, relay=none,

    delay=2601, delays=2601/0.01/0/0, dsn=4.3.0, status=deferred (mail transport unavailable)

    Any idea would be most appreciated.

  35. Davo says…

    I just tried this on my macbook pro and when I enttered sudo nano -w /etc/hostconfig into terminal it said no such file found

    I am running xampp on 10.6.7

  36. chandishwar says…

    i followed your tutorial step by step.
    in second step when i run this command.
    sudo nano -w /etc/postfix/
    im not finding the myhostname variable.
    please help me .

  37. andy says…

    Hey all, unfortunately these questions are outside of the scope of my knowledge, this is all compiled from other solutions I used that I found via Google.

    Good luck and sorry I can’t help further!

  38. PHP mail() using Sendmail on Mac OS X Leopard (10.5.8) says…

    […] […]

  39. Daza Grohovaz says…


    i use Mountain Lion with the Server Application.
    looking in the mail.log file, i just realized that MacOSX Server didn’t set all rights like i should do…

    1. look in the log file

    tail -f /var/log/mail.log

    2. if you get this message, you have the same problem that i had

    Oct 3 11:48:54 MacOsX.Server postfix/postfix-script[59779]: warning: not owned by _postfix: /Library/Server/Mail/Data/mta/./guid_device_maps.plist

    3. check the rights and privileges of the file guid_device_maps.plist

    sudo ls -al /Library/Server/Mail/Data/mta/./guid_device_maps.plist
    -rw-r—– 1 root mail 181 Sep 18 07:40 /Library/Server/Mail/Data/mta/./guid_device_maps.plist

    4. change the owner to _postfix user

    sudo chown _postfix /Library/Server/Mail/Data/mta/./guid_device_maps.plist

    5. check your changes πŸ˜‰

    sudo ls -al /Library/Server/Mail/Data/mta/./guid_device_maps.plist
    -rw-r—– 1 _postfix mail 181 Sep 18 07:40 /Library/Server/Mail/Data/mta/./guid_device_maps.plist

    6. open the Server Application, go to Email, check the Authentication method, i set it as “Automatic”

    7. finally restart it switching on/off

    sorry if the description isn’t 100% correct, i have my system in german, but i think you know what i mean…


  40. Getting mail() function to work on PHP via OS X Server | All things me says…

    […] (Courtesy of this post.) […]

  41. thekliar says…


  42. MAC OS Mountain Lion configure Postfix Sendmail Link Collection says…

    […] The tutorial for Mountain Leopard […]

  43. used cars dealerships in las vegas says…

    When I originally left a comment I seem to have clicked on the -Notify me when new comments are added- checkbox and now whenever a comment is added I recieve four emails with the same comment.
    Perhaps there is a means you can remove me from that service?
    Many thanks!

  44. PHP mail() using Sendmail on Mac OS X Leopard (10.5.8) - PHP Solutions - Developers Q & A says…

    […] […]

  45. Matt says…

    Thanks dude! You rock!

RSS feed for comments on this post. TrackBack URL

Leave a Comment

July 6, 2009

Filed in Development

There are 45 comments »

« Back to the Blog