I'm building a website that sends and email to a user when he registers.
My code (the gist of it):
<?php $to = "email@example.com"; $subject = "Test mail"; $message = "Hello! \nThis is a simple email message."; $headers = "From: firstname.lastname@example.org"; $headers .= "\r\nReply-To: email@example.com"; $headers .= "\r\nX-Mailer: PHP/".phpversion(); mail($to,$subject,$message,$headers); echo "Mail Sent."; ?>
the problem is that when the mail is delivered, the from header remains
firstname.lastname@example.org, 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?
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
A workaround for valid addresses that works with many ISPs:
try adding a fifth parameter to your
It turns out the original poster's server (blueHost) has a FAQ concerning this very question.
This is because our servers require you (or your script) to use a properly formatted, valid From: field in the email's header. If the From: field is not formatted correctly, empty or the email address does not exist in the cPanel, the From: address will be changed to
You must change the script you are using to correctly use a valid
Examples of headers that should work would be:
From: "user" <email@example.com>
Examples of headers that will NOT work:
From: user @ domain.com
From: firstname.lastname@example.org <email@example.com>
Our servers will not accept the name for the email address and the email address to be the same. It will not accept a double declaration of the email address.
For scripts such as Joomla and Wordpress, you will need to follow their documentation for formatting the from fields properly. Wordpress will require the Mail From plugin.
Note: The email address you use must be a valid created account in the cPanel.