Page 1 of 1

[SOLVED]Mail() problem

Posted: Tue Jan 11, 2005 8:36 am
by Jean-Yves
Could you help out with the following? I am getting this error:
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in path_to_script.php on line 410
(scriptname/path changed for security)

The code for mailing is as follows:

Code: Select all

$mailBody .= "Your King/Queen has been slain in the following game:\n\n";
              $mailBody .= $game->getDescription();
              $mailBody .= " on day " . $game->getDay() . "\n\n";
              $mailBody .= "Better luck next time!";
              $mailBody .= "THIS IS AN AUTOMATED MESSAGE - PLEASE DO NOT REPLY TO THIS EMAIL\n";
              $mailBody .= "(All correspondence sent to this e-Mail address will be ignored)\n\n";

              $mailHeaders = "From: " . $AUTOMATED_EMAIL . "\r\n"; // From address
              $mailHeaders .= "Reply-To: " . $AUTOMATED_EMAIL . "\r\n"; // Reply-to address
              $mailTo = $eMail;
              $mailSubject = htmlspecialchars("The end has come in: " . $game->getDescription());

              mail($mailTo, $mailSubject, htmlspecialchars($mailBody), $mailHeaders);
Line 410 is the last line, the one with mail() in it. $eMail, $game and $AUTOMATED_EMAIL are all correctly set.

I am using almost identical code elsewhere (subject and mail body are different), with no errors. Hopefully it's an obvious error that I'm just not seeing due to staring at it for too long! :wink:

Thanks

Posted: Tue Jan 11, 2005 12:22 pm
by abshaw
as you have mentioned the error is indicating towards the php.ini setings, one thing to do is check for your smtp settings in the php.ini file and then check it through phpinfo().

it also matters what kind of server you are using for smtp, exchange, neo, sbc, vodacom...

Posted: Wed Jan 12, 2005 9:00 am
by Jean-Yves
Thanks. Everyhting appears OK at the server end, and there are 5 other scripts using almost identical code which work fine.

Baffling.

Posted: Wed Jan 12, 2005 9:28 am
by ianlandsman
You might also want to check out a really good mailer class called phpmailer. You can do the search on google. It makes sending out emails really easy as well as adding attachments, etc

Posted: Wed Jan 12, 2005 9:17 pm
by Shendemiar
Use something trivial for subject and body. If it works, it's either of them. Use same method to check which one.

Use these values in some other mail(), maybe you forgot to include/set something in this file.

Posted: Thu Jan 13, 2005 6:45 am
by Jean-Yves
Robert, you actually have the code, it's in the zip that I sent you a while back - would you mind looking at the battle script and seeing if anything is amiss, compared to say, the contact script or the end turn script, both of which fire off emails correctly?

I did take the code out of the script and run it on its own. Worked fine. And yet I know that the original script (battle) fires this code, as I've echo/died just after and all the values are correct...... :?

Posted: Thu Jan 13, 2005 7:12 am
by Jean-Yves
Oh good grief! I do believe that I have may have been a bit of a plonker!

The answer was there all along.... The, ahem, cough, cough... "To Email" value may have been, shall we say, errr - removed from the query a few dozen lines above it? When I took the script out and tested it stand alone I hard coded a value. You wouldn't know that I've been doing this computing thing for over twenty years, now would you?!

:oops: :oops: :oops: :D