I have configured my server to send mail by setting "sendmail_path = "/usr/sbin/sendmail"
in "/etc/php5/apache2/php.ini" and sendmail is installed on the server.
When I run this script, or any variation of it, from php5 via the cli the mail sends just fine, but when I have a browser run it, i.e. Chrome or Firefox, it fails everytime.
<?php
$to = "notreal@email.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
I am using the "php5-cli" package for a command line interpreter.
Other PHP based web-apps that rely on the PHP "mail()" function don't send mail either.
Apache and the CLI seem to use different configurations in your setup.
Compare the configuration in /etc/php5/cli/php.ini
with your Apache's php.ini
. Probably something is not working with the sendmail configuration for Apache's PHP and the CLI configuration is right.