tyooseph Posted January 16, 2009 Share Posted January 16, 2009 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/141079-mail-returns-true-even-without-header-information/ Share on other sites More sharing options...
micmania1 Posted January 16, 2009 Share Posted January 16, 2009 mail() cannot tell whether or not a message has been delivered. mail() can also work without headers. PHP Mailer Quote Link to comment https://forums.phpfreaks.com/topic/141079-mail-returns-true-even-without-header-information/#findComment-738368 Share on other sites More sharing options...
Zephyr_Pure Posted January 16, 2009 Share Posted January 16, 2009 Put the mail() function inside an if conditional and check to make sure !empty(headers). That should at least help some with your problem. Quote Link to comment https://forums.phpfreaks.com/topic/141079-mail-returns-true-even-without-header-information/#findComment-738375 Share on other sites More sharing options...
tyooseph Posted January 16, 2009 Author Share Posted January 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/141079-mail-returns-true-even-without-header-information/#findComment-738377 Share on other sites More sharing options...
Zephyr_Pure Posted January 16, 2009 Share Posted January 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/141079-mail-returns-true-even-without-header-information/#findComment-738600 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.