tags:

views:

179

answers:

3

I am using php, using mail function:

$headers =  'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: [email protected]' . "\r\n";
$headers .= 'Reply-To: Admin <[email protected]>' . "\r\n";

// Return Path - 
$return_path = "[email protected]";

$toUser... (all necessary variables)

if(mail($toUser,$subject,$body,$headers, "-f".$return_path)){
    echo "res=sent";
} else {
    echo "res=error";
    }

I tested few emails like, [email protected], [email protected]

(etc, all invalid, non-existent email addresses)

Why it dont go to my [email protected]????

A: 

You need to add a space after -f. Also, why not use UTF-8 instead of iso-8859-1? Try this:

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'From: [email protected]' . "\r\n";
$headers .= 'Reply-To: Admin <[email protected]>' . "\r\n";

// Return Path
$return_path = '[email protected]';

/*
$toUser... (all necessary variables)
*/

if(mail($toUser, $subject, $body, $headers, '-f ' . $return_path)) {
 echo 'res=sent';
} else {
 echo 'res=error';
}
Mathias Bynens
i added space after "-f" and change charset to UTF-8, but it still does not work. I mean, my [email protected] still didnt receive any bounce email. Do you have any other ideas?
can you provide more solution? I have run out of ideas.. Read my code couple of times... It just wont bounce back...
You don't need the space. The PHP manual example doesn't have a space and if you look at the documentation for sendmail the parameter doesn't need a space. I also just tested it without a space and it worked.
Tom Haigh
A: 

It may be caused by the configuration of your sendmail. The -F parameter is piped through as a command line attribute, so sendmail needs to be configured to support it.

From php.net:

The additional___parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option.

Edit: I just saw that Matthias Bynens' answer is correct, see this entry

Treb
+1  A: 

You should also be able to set the Return-Path using a header on most servers:

$headers .= "Return-Path: [email protected]\r\n";
miknight