tags:

views:

352

answers:

3

Hi,

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! \nThis is a simple email message.";

$headers = "From: [email protected]";
$headers .= "\r\nReply-To: [email protected]";
$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 [email protected], while reply-to gets changed to the specified value.

box347.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?

Thanks,
jrh

+2  A: 

In order to prevent phishing, some mail servers prevent the From from being rewritten.

Luís Guilherme
Lots of ISPs do this now
Erik
True, but it should be possible to use a domain as sender name that is registered to that server. Forcibly overwriting *anything* to the basic hostname of the server is ridiculous.
Pekka
+3  A: 

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]");
Pekka
I'm actually not using "From: [email protected]". I'm using some other address, but I guess your point is that the server will not allow me to send a mail as just some random person. but that is so wrong!
Here Be Wolves
Sorry mate, but that is so, so right! Check your spam folder for supporting evidence. :)
Pekka
hmm, I realize you are right.
Here Be Wolves
so I contacted the admin for our web host and had the reqd email id added as "authorized". Now it works. Thanks!
Here Be Wolves
A: 

The web host is not really playing foul. It's not strictly according to the rules - but compared with some some of the amazing inventions intended to prevent spam, its not a particularly bad one.

If you really do want to send mail from '@gmail.com' why not just use the gmail SMTP service? If you can't reconfigure the server where PHP is running, then there are lots of email wrapper tools out there which allow you to specify a custom SMTP relay phpmailer springs to mind.

C.

symcbean