Surprisingly, I hadn’t noticed until just yesterday when I was testing out a contact form for a website under development that my PHP mail() wasn’t working properly. I really should have — WordPress sends out moderation emails for comments, and the absence of those in testing should have made me think twice, but it didn’t.
So, PHP and Sendmail weren’t playing nice. The default command is sendmail -t -i, if you don’t manually set sendmail_path in your php.ini configuration, but this wasn’t working.
Unfortunately, due to some degree of stupidity in the way things are run, you need to use an absolute path for PHP to find where it is (even if just the command “sendmail” works fine from a terminal… like I said, stupid), so if you want mail, you have to play by its rules. For no apparent reason.
This is all with stock Ubuntu versions of Apache2 and PHP, by the way — the stupidity may go away if you do-it-yourself, but I’m kind of doubting it.
Anyway, assuming you’ve got sendmail (or an MTA which provides sendmail hooks — I’m actually using postfix here) installed, you can simply set this in your php.ini, restart Apache (using apache2ctl restart from a root account), and all should be working:
sendmail_path = /usr/sbin/sendmail -i -t
Bingo!

Wow, that’s a really useful tip. I can’t believe one has to specify a static path to sendmail within the php.ini. Mad.
I’ve still got a few issues with localhost.localdomain on php mail, but this was very good to know.
[…] cribbed from here and here. Active Directory Aging Baby Bass Birthday Blogs Books Change Choices Cold […]
Its nice
It works for me.
Thank you.
Just a little comment: PHP requiring full path to sendmail (actually, any other binary) actually makes perfect sense:
when running sendmail from a terminal the binary is found by looking into $PATH. PHP can’t count on that being defined for itself, thus it needs the full path to the binary (just as you would need to type if you hadn’t a properly defined $PATH).
Hope this clarifies a little bit.
Wonderful,
I used a full path to /usr/sbin/ssmtp, it worked with a command shell but not with a script. It’s really stupid!
thank you
Superb, thanks for that, that saved me hours of headache!
Matt