Jump to content

Mail() returns true even without header information


tyooseph

Recommended Posts

The mail() result returns true (or 1) regardless of if the email is sent or 'accepted for deliver' (per php.net).  According to php.net, mail() should not work without a proper header.  However, if I comment out the $header line in my code below, mail() still returns true.  I checked php.ini and sendmail_from is not set.  (In case it matters, I'm running on localhost.)

 

The code works, but I need to know when it fails.  Reason I'm checking mail() is to inform the $requester that their request has been sent; otherwise, to display message for them to call.

 

Here's what I've got...

 

$to = [email protected], [email protected], [email protected]';

$subject = "Request Received From: $requester";

$headers = "From: [email protected]\r\nCc: [email protected]";

$message = "A request has been received from the subject property.\n\n

To review information, please click on the following link:\n

http://www.test.com/review.php?x={$_GET['id']}\n";

$message = wordwrap($message, 70);

$message = str_replace ("/n.", "/n..", $message);

 

$mail_sent = mail($to, $subject, $message, $headers);

 

echo "<p>Msg Sent: $mail_sent</p>";

response to micmania1 - www.php.net states the FROM is required or failure occurs.

 

Note: When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.

Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.

 

 

 

response to micmania1 - www.php.net states the FROM is required or failure occurs.

 

Note: When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.

Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.

http://us3.php.net/manual/en/function.mail.php

 

It's an optional argument to the function... as long as the php.ini has a default set.  A lot of webhosts have this configured already.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.