Jump to content

[SOLVED] Mail() setting From and Return-Path


kandi_nyc

Recommended Posts

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.

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.)

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!!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.