[SOLVED]Mail() problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

[SOLVED]Mail() problem

Post 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
Last edited by Jean-Yves on Thu Jan 13, 2005 7:12 am, edited 1 time in total.
abshaw
Forum Commoner
Posts: 33
Joined: Thu Feb 19, 2004 7:14 pm

Post 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...
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post 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.
ianlandsman
Forum Newbie
Posts: 24
Joined: Thu Dec 30, 2004 9:50 pm
Location: New York

Post 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
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post 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.
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post 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...... :?
User avatar
Jean-Yves
Forum Contributor
Posts: 148
Joined: Wed Jul 02, 2003 2:13 pm
Location: West Country, UK

Post 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
Post Reply