Thursday, May 28, 2009

PHP Mail on Windows Server

I had a weird problem with my PHP mail() function on a windows server. When I was trying to send the emails, the email headers would show up in the body of the email itself. After a lot of frustration, I figured out a solution that worked for me.

After each header, you usually add a "\r\n". It seems like the \n was giving us the problem so I took it off. So after each header I had instead "\r". It worked... so there you go.

For example:

$headers = 'From: someemail@email.com' . "\r";
$headers .= 'MIME-Version: 1.0' . "\r";
$headers .= 'Reply-To: replytoemail@email.com' . "\r";

No comments: