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
hello i have done the following :
1.install sendmail and configure /etc/mail/sendmail.mc :
add comment to line DAEMON_OPTIONS(‘Family=inet, Name=MTA-v4, Port=smtp, Addr=127.0.0.1′)dnl
2.configure joomla mail server sitting = sendmail
3.php.ini :
sendmail_path = /usr/sbin/sendmail –i –t
mail server only working if i send email from local server , but when am trying send email from website via Internet that not working !!!
*** ANY HELP
Hi moata_u,
When you say via Internet, do you mean it’s on another server? You’ll need to make sure your web host also has sendmail support — many require you to use SMTP to another mailserver these days.
Cheers,
Josh
I have installed sendmail by:
sudo apt-get install sendmail
Then I changed the php.ini file:
sendmail_path = /usr/sbin/sendmail –i –t
Email still don’t send from my site
Thanks much for sharing! Worked like a charm.
I have the same proble as steveo, I have postfix and changed the php.ini and the return of mail() es success(1) like everything is working ok. but the problem is than the mail never arrive to my account, in /var/log/apache2/error.log isn’t problems.
can some body help me? i don’t know where search the problem.
Before Hand Thanks!
I have the same problem as steveo and carlosalvet .…
It’s possible your ISP has some kind of port blocking going on preventing you from sending outbound mail… do you know what their policy is on this?
Finally got mail for PHP working…
Thank you!
Ben Sampson! How did you solve? I would like to learn the CMS: Drupal and have a problem with php sendmail.
The XAMPP is installed
THe sendmail is installed (as how described above)
The php.ini was modified (as how described above)
I tried with a simple php code:
When I call this code with my browser, it waits a long time for localhost and finally I get the answer: “Mail Sent” , but the email doesn’t arrive.
If anybody has the solution, please let me know.
Thanks!
p.s.: I use Ubuntu 11.04 64bit