How to set correct mail headers when sending emails from a php page?
- mail() function in php used to send emails via apache
- manual of this function is here
- first 3 arguments to this function are required, rest optional
- the following problem is seen with bounced emails:
- since the Return-Path header field is set to apache@wwwphy.princeton.edu, by default, the person/webpage that generated the original email does not see the bounce
- 4th (optional) field is for additional headers. Setting appropriate Return-Path header here does NOT work. "From" header specification works fine here
- The trick is to pass an additional parameter (5th) to the mail() function, which ultimately gets passed on to sendmail
- here you can specify the -f option, which asks sendmail to set the desired Return-Path header. e.g:
mail($address,$subject,$message,"From: netid@princeton.edu",'-fnetid@princeton.edu');
