I'm using PHPMailer with Sendmail. I can send email, but the mail() function returns false although the mail was sent. Why is this happening and how can I fix it?
The problem is with Sendmail (the sendmail qmail wrapper) returning the value -1 when it should be returning the value 0.
The problem only occurs if you include the -f parameter, but the -f email address is not set up on the local machine. This is a snip of example code:
if ( mail( 'admin@yourdomain.com', 'test', 'test2', 
"From: webmaster@$SERVER_NAME\r\nReply-To: 
webmaster@$SERVER_NAME\r\nX-Mailer: PHP/" . phpversion(), 
"-fuser@yourdomain.com" ) ) {
    echo "mail sent okay";
}
else {
    echo "mail cannot be sent!";
}
PHP is running on the same machine as the yourdomain.com domain.  If the user 'user' hasn't been set up, then sendmail will complain:
sendmail[21956]: JAA21956: setsender: 
user@yourdomain.com: invalid or unparseable, received from httpd@localhost
However, it will still send the mail. So essentially, sendmail is returning an error code, but still sending the mail.
The solution is to make sure the -f email address is set up on the local machine.
