kandi_nyc Posted September 20, 2008 Share Posted September 20, 2008 Hi - I have a web form where users can "tell a friend" about the site. The form accepts the sender's email address (person filling out the form) and the sender's email address. I need the sender's email address to be in the "From" field and not an email address from my domain. However, when I do this, emails do not get sent out. If I change the "From" field to be and email address on my domain, it gets sent. My host provider said I need to add an email address from my domain as the return-path then I can set any email address for the "From" field. When I do this the email does get sent however, the email address that is received has a the return-path appended to the sender's email address like such: FROM: [email protected] : [email protected] I only want [email protected] to be displayed in the FROM. How can I accomplish this? Here is the code snippet I am using $from = '[email protected]'; $subject = $headline; $headers .= 'From: '.$from.'\r\n'; $headers .= 'Return-Path: [email protected]\r\n'; $headers .= "Content-Type: text/html"; $mail_sent = @mail( $from, $subject, $email_msg_sender, $headers); I've also tried doing it the following way but nothing gets sent. $mail_sent = @mail( $from, $subject, $email_msg_sender, $headers, "[email protected]"); Any advise is much appreciated. Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/125096-solved-mail-setting-from-and-return-path/ Share on other sites More sharing options...
Stooney Posted September 20, 2008 Share Posted September 20, 2008 You need double quotes around the \r\n $headers .= 'From: '.$from."\r\n"; $headers .= "Return-Path: [email protected]\r\n"; Link to comment https://forums.phpfreaks.com/topic/125096-solved-mail-setting-from-and-return-path/#findComment-646495 Share on other sites More sharing options...
PFMaBiSmAd Posted September 20, 2008 Share Posted September 20, 2008 The Return-Path is the address that error messages (bounce messages) are supposed to be sent to. What you should be setting is the Reply-To: address. The From: address should be a valid mail box on your sending mail server (so that your sending mail server will send it and the receiving mail server will accept it.) The Reply-to: address should be the address you want replies to be sent to (when the receiver clicks on the reply button in his mail client.) Link to comment https://forums.phpfreaks.com/topic/125096-solved-mail-setting-from-and-return-path/#findComment-646505 Share on other sites More sharing options...
kandi_nyc Posted September 20, 2008 Author Share Posted September 20, 2008 Thanks for your feedback however what I'm trying to accomplish I guess is similar to what NewYorkTimes.com does. Emails are received in the inbox with [email protected] and when you open the email, the FROM field reads as follows: From: emailaddrr@newyorktimes on behalf of [email protected] This is exactly what I'm trying to do. How to I get the "on behalf of" someone done using PHP? Thanks again!! Link to comment https://forums.phpfreaks.com/topic/125096-solved-mail-setting-from-and-return-path/#findComment-646549 Share on other sites More sharing options...
kandi_nyc Posted September 22, 2008 Author Share Posted September 22, 2008 For anyone else who might need to do this ... add a "Sender" header. From and reply-to headers can be any address not on your domain. return-path and sender headers must be an email address on your domain. Link to comment https://forums.phpfreaks.com/topic/125096-solved-mail-setting-from-and-return-path/#findComment-647661 Share on other sites More sharing options...
PFMaBiSmAd Posted September 22, 2008 Share Posted September 22, 2008 From and reply-to headers can be any address not on your domain. return-path and sender headers must be an email address on your domain. For at least the From: address, that statement being true is dependent on how your mail server is setup and on what the the receiving mail server is setup to check. Link to comment https://forums.phpfreaks.com/topic/125096-solved-mail-setting-from-and-return-path/#findComment-647665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.