When using PHP to send email, how can I set the return path for receiving bounced back emails?
There is a parameter in mail()
that allows user to set additional headers. You should set a "Return-Path" header, like this:
mail($email, $subject, $message,
"From: $returnaddress
"
. "Reply-To: $returnaddress
"
. "Return-Path: $returnaddress");
To get this to work on my server (bluehost) I had to also use the fifth parameter (i.e. "$additional") as shown below:
$headers = "From: joe.smith@shaw.ca
Reply-To: joe.smith@shaw.ca";
$additional = "-rjoe.smith@shaw.ca";
mail("fred.jones@shaw.ca", "Subject", "Message",$headers, $additional);