PHP mail() -f parameter is NOT working

the mail() function

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Tue May 08, 2012 5:00 am

PHP mail() -f parameter is NOT working

Postby Pavilion » Thu Jul 05, 2012 4:14 pm

After much research, I've figured out that one needs to use an -f parameter with the php mail() function, if one wants undeliverable mail to bounce back. Following is my script (as it stands now):

Code: Select all

      //Send Confirmation email. Following are the variables for the email
      // mail function best practices:
      $sendto = $email; // this is the email address collected from the foreach routine.
      $e_subject = stripslashes($subject); // Subject
      //$message = "<html>" . stripslashes($body) . "</html>";
      $message = "
         <p>Hello " . stripslashes($fName) . ":</p>
         <div>" . stripslashes($body) . "</div>
      // Always set content-type when sending HTML email
      $header = "MIME-Version: 1.0" . "\r\n";
      $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";;
         // extract user domain so you can set up X-Mailer
         $u_domain=substr(strrchr($user_email, '@'), 1);
         $dom_array = explode(".",$u_domain);
         $user_domain = $dom_array[0]; 
      $header .= "X-Mailer: ". $user_domain ."\r\n";   
      $header .= "X-Sender-IP: {$_SERVER['REMOTE_ADDR']}\r\n";
      $header .= "X-Originating-IP: [".getenv("REMOTE_ADDR")."]\r\n";
      $header .= "From: " . $user_email . "\r\n";
      $header .= "Sender: ". $user_email . "\r\n";
      // The "envelope sender" is the address listed in the "Return-Path:" header - and controls where the email is sent to in the event that a recipient address bounces.
      $header .= "Return-Path:" . $user_email . "\r\n";
      $header .= "Reply-To:" . $user_email . "\r\n";
      $bounceTo = "-f ". $user_email;
      // Collect variables from above and insert into the mail() function.
      mail($sendto, $e_subject, $message, $header,$bounceTo);

Firstly I made sure to use the strtolower() function on the user email. So.. the value passed to $user_email is lower case.

Also, you'll notice a lot of commenting - I'm just trying to figure this out. My mail() sends wonderfully. The mail is coming into my inbox with formatting as it should be.

But... the $bounceTo variable ("-f" . $user_email) is not working. I've intentionally mailed to 3 known inactive addresses, and I'm not getting any bounce backs.

All the header settings in the above code are in place because I've learned that these may affect bounce backs. I'm totally willing to get rid of un-necessary headers and add what is necessary. But... at this point the script seems to be a mess -which is not producing bounce backs.

Any suggestions are welcome.

Thanks Much:


New php-forum User
New php-forum User
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm

Re: PHP mail() -f parameter is NOT working

Postby kyle04 » Tue Jul 17, 2012 4:45 am

Have you tried :

mail($sendto, $e_subject, $message, $header,'$bounceTo');

ie, $bounceTo variable in quotes.


php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: PHP mail() -f parameter is NOT working

Postby johnj » Wed Jul 18, 2012 11:21 pm

Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest