PDA

View Full Version : PHP mail() header problem



gil.r21
02-20-2010, 04:10 AM
Hi all
I have a hostmonster acount
and in one of my scripts I am sending emails via the mail() function.
I also have email box setup on my account.
The problem is that I am trying to define the headers like this


$header = "MIME-Version: 1.0 \r\n";
$header.= "Content-type: text/html; charset=UTF-8 \r\n";
$header.= "From: xxx@email.org\r\n";
$header.= "reply-to: no answer <no-answer@intern.org.il> \r\n";

but when it sends the email I am getting it like from: *email*@host394.hostmonster.com

pls help
Gil

shadmego
02-20-2010, 09:55 AM
You said you have email box set up on your account.

Does this mean you have the address "xxx@email.org" created for your account? If not, then you will have to create that address for it to show up in the From field.

~regards

gil.r21
02-20-2010, 11:29 AM
Hi
I have an actuall address created for my account
and I am trying to make it show on the emails I send by defining it in the mail header
but it doesn't show on the sent email... instead it shows the email was sent by myusername@hostmonster.com, instead of my existing mailbox assigned to my domain name.

sjlplat
02-20-2010, 11:40 AM
Remove the \r from your linefeeds. Carrier Returns are unnecessary for Linux boxes.

Try this:


$header = "From: Your Name <xxx@email.org>\n";
$header .= "Reply-To: no answer <no-answer@intern.org.il>\n";
$header .= "Return-Path: xxx@email.org\n";
$header .= "Envelope-from: xxx@email.org\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/html\n";

gil.r21
02-20-2010, 12:26 PM
It works
thanks so much guys

shadmego
02-22-2010, 07:58 AM
[QUOTE=sjlplat;32986]Remove the \r from your linefeeds. Carrier Returns are unnecessary for Linux boxes.


That's interesting. I've recently written a fairly massive website (still building) and in using php's mail(), I tried to originally use "\n". It failed to work properly unless I added the "\r\n".

And as I write this, I believe the box I am working on is a Windows box running PHP .... well, there goes this post ....

sjlplat
02-22-2010, 11:56 AM
That's interesting. I've recently written a fairly massive website (still building) and in using php's mail(), I tried to originally use "\n". It failed to work properly unless I added the "\r\n".

And as I write this, I believe the box I am working on is a Windows box running PHP .... well, there goes this post ....

Correct. \r is required for Windows boxes. :)