Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm building a website that sends and email to a user when he registers.

My code (the gist of it):

<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! 
This is a simple email message.";

$headers = "From: [email protected]";
$headers .= "
Reply-To: [email protected]";
$headers .= "
X-Mailer: PHP/".phpversion();

mail($to,$subject,$message,$headers);

echo "Mail Sent.";
?> 

the problem is that when the mail is delivered, the from header remains [email protected], while reply-to gets changed to the specified value.

box123.bluehost.com is the hostname of the server on which the website is hosted.

So what am I doing wrong? What can I do to get the "From" address the same as the reply-to address?

Is it something I'm doing wrong, or is the web host playing foul?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
982 views
Welcome To Ask or Share your Answers For Others

1 Answer

Edit: I just noted that you are trying to use a gmail address as the from value. This is not going to work, and the ISP is right in overwriting it. If you want to redirect the replies to your outgoing messages, use reply-to.

A workaround for valid addresses that works with many ISPs:

try adding a fifth parameter to your mail() command:

mail($to,$subject,$message,$headers,"-f [email protected]");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...