0

I've researched this intensely. Here, at Stack Overflow, 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):

//Send Confirmation email. Following are the variables for the email 
// mail function best practices: http://collaborate.extension.org/wiki/Best_Practices_Using_the_PHP_mail_Function

$sendto = $email; // this is the email address collected from the foreach routine. 
$e_subject = stripslashes($subject); // Subject 
//$message = "<html>" . stripslashes($body) . "</html>";
$message = "
    <html>
    <body>
    <p>Hello " . stripslashes($fName) . ":</p>
    <div>" . stripslashes($body) . "</div>
    </body>
    </html>
    ";  
// 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. http://collaborate.extension.org/wiki/Best_Practices_Using_the_PHP_mail_Function
$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);

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:

Pavilion

Pavilion
  • 1
  • 1

3 Answers3

0

Have you looked at the comment posted at http://www.php.net/manual/en/function.mail.php#107321. That might lead you in the right direction.

jg314
  • 586
  • 1
  • 6
  • 15
  • The one at http://www.php.net/manual/en/function.mail.php#94170 may also be helpful for you. – jg314 Jul 05 '12 at 22:13
  • Yes - I reviewed that post before posting here. All bounces should take the same return-path as From, so the suggestions in that post are not applicable. – Pavilion Jul 05 '12 at 23:55
0

This thread explaining bounced mail in php might be of benefit to you. I personally have never had to use the -f parameter to handle bounced emails.

Community
  • 1
  • 1
Richard Ye
  • 685
  • 4
  • 12
  • Yes - I've reviewed that thread - and it really isn't the same kind of application as mine. The bounce back email address will change with every user. – Pavilion Jul 05 '12 at 23:59
0

Overriding the bounce address with -f is not allowed on all servers, especially if you are on a shared hosting server this is often not possible. In this case, it's often better not to use the very limited mail() function but use a smtp library like phpmailer or swiftmailer instead.

Btw: you don't have to send mails to an inactive address to check your bounce address. Send them to an active account, in the message source look for the "Return-Path" header, this is the bounce address.

Gryphius
  • 75,626
  • 6
  • 48
  • 54
  • OK - I just tried phpmailer and it causes more problems than it solves: – Pavilion Jul 06 '12 at 15:03
  • OK - I just tried phpmailer and it causes more problems than it solves: 1. Still not getting bounced email back. 2. Using a variable to pass user entered content to the body, the body is NOT picking up user entered content. 3. Body is picking up a 1st standard paragraph, but it is NOT going through as html. One can see the html tags as if they were part of the text itself. 4. Previously the mail() function was sending an email address to each recipient with ONLY that recipient's name in the TO:. Now (with phpmailer) the TO contains names of All recipients - that's NOT a good thing. – Pavilion Jul 06 '12 at 15:11