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 = staffone@arb.ca.gov, stafftwo@arb.ca.gov, staffthree@arb.ca.gov';

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

$headers = "From: test@xxx.arb.ca.gov\r\nCc: me@arb.ca.gov";

$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>";

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.