Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php mail() returning false, but not in command line

I've been looking around on stackoverflow and many other websites for ideas, but nothing has worked so far and I need more direct help.

I have a dedicated Ubuntu Server (9.04 jaunty) and I'm running several PHP websites there, with apache2. My problem is that the mail() function has stopped working. Since a while back I've been using PEAR Mail Queue for most emails, so I'm not sure exactly when mail() stopped working, but I still need it for an OpenCart setup, among a few other things, but mail() keeps return false no matter what I do. Even this simple code won't work:

<?php
mail('[email protected]','test','test');
?>

So, I've been looking at the Sendmail-settings in php.ini which all check out, and when I run this in the command line, it works fine and sends me an email:

# sendmail
[email protected]
test message

So I thought it might be php itself that has a problem, so I try the following command:

# php -r "mail('[email protected]','test','test');"

And it also sends the email without any problems! So what could it be? I started thinking it might be some sort of permission problem, that maybe www-data had some issues with running the script. Still not sure about this, because I can't even run this script:

<?php
echo exec('whoami');
?>

It also returns false! I've run the visudo command and added the following line just in case:

www-data ALL=(ALL) ALL

And I've changed the user and group owners of the files from root:root to www-data:www-data but still nothing!

What else can I try? There must be someting! Can anyone help me?

like image 962
user1663164 Avatar asked Sep 11 '12 14:09

user1663164


1 Answers

Commandline and webserver don't share the same php.ini! Check which php.ini is used on commandline and in the server module.

like image 124
powtac Avatar answered Nov 09 '22 23:11

powtac