Simple php scripts fail to send mail and the mail() function consistently returns false. (A simple test script to install is included at the end of this post.) When you look at the error logs in /var/log, you can't find anything that indicates why your mail is failing.
On my server, this is what (basically) I have: Suse 9.3Pro, SendMail, Apache2, PHP4, and sending mail was failing with the appearance that php->mail() was never passing the arguments of the mail function to the sendmail application.
SOLUTION
You probably have one of the two following lines in your /etc/php.ini file:
sendmail_path =
or
sendmail_path = '/usr/sbin/sendmail -t -i'
What you need to do is change the sendmail path to:
sendmail_path = "/usr/sbin/sendmail -t -i"
(note the double quotes replacing the single quotes)
Stop and restart your Apache server so the new php.ini values are read. You should be good to go after this.
Hope this helps someone - I spent a couple of days knocking my head against the desk trying to figure out this one. Sometimes, it's the simple solutions that really throw you for a loop.
--Mike
<?php
$ret = "";
if (!function_exists("mail"))
die("mail() does not exist on this server.");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</HEAD>
<BODY>
<?php
echo "\$ret = mail(\"foo@bar.com\", \"testing php->email\", \"this is a test\", \"-f root@bar.com\");";
$ret = mail("foo@bar.com", "testing php->email", "this is a test", "-f root@bar.com");
echo "<BR/>mail() returned: " . ($ret? "TRUE" : "FALSE") . "<BR/>";
?>
</BODY>
</HTML>
Edited by mshallop, 02 August 2005, 18:39.














