Forum Moderators: coopster

Message Too Old, No Replies

Mail headers

quit working after server migration

         

mike73

8:33 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



Hi everybody,

I recently moved all my sites to a new dedicated server. Now all of my PHP mail headers, which worked fine before, appear in the message body.

Does anybody know why?

Thanks in advance!
Mike

jatar_k

4:06 am on Jul 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe post the headers you are using

I had this problem once, maybe seeing the code will jog my memory

mike73

7:52 am on Jul 3, 2006 (gmt 0)

10+ Year Member



Here's the code:


$headers = "From: info@mydomain.com\r\n";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "@mydomain.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "Date: ".date("D, d M Y H:i:s") . " UT\r\n";
$headers .= "Reply-To: info@mydomain.com\r\n";
$headers .= "Return-Path: info@mydomain.com\r\n";
$headers .= "X-Priority: 3\r\nX-MSMail-Priority: Normal\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";
$headers .= "X-MimeOLE: Produced By MyDomain\r\n";
$success=mail($to, $s_subject, $s_emailmsg, $headers);

Only the "MIME-Version" and the three "X-..." hearders appear in the message body. The other weird thing is that this only happens in Outlook. The mail looks normal in Hotmail.

dreamcatcher

8:09 am on Jul 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi mike73,

I had someone with a similar problem a while back and what they did was they moved the content-type header to parse last. Its a long shot, but give it a try:


$headers = "From: info@mydomain.com\r\n";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "@mydomain.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Date: ".date("D, d M Y H:i:s") . " UT\r\n";
$headers .= "Reply-To: info@mydomain.com\r\n";
$headers .= "Return-Path: info@mydomain.com\r\n";
$headers .= "X-Priority: 3\r\nX-MSMail-Priority: Normal\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";
$headers .= "X-MimeOLE: Produced By MyDomain\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$success=mail($to, $s_subject, $s_emailmsg, $headers);

dc

mike73

9:48 am on Jul 3, 2006 (gmt 0)

10+ Year Member



Thanks for the tip, dreamcatcher, but that didn't work either :(

I'm guessing there must be a switch or a setting in sendmail that is messing it up, but I have no idea what.

According to to phpinfo, I running sendmail with two flags
-i
-t

but they don't seem to be the problem.

Where else should I look?

Sekka

10:17 am on Jul 3, 2006 (gmt 0)

10+ Year Member



I had pretty much the same problem.

What I discovered, after much testing, was that my PHP server didn't support the MIME type and couldn't actually send it with the mail () PHP function. Or that was what I was told.

The only solution I could find to my problem is to send the email through an SMTP connection.

Hope this helps.

mike73

12:23 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



Thanks, Sekka, I'll look into that.

The strange thing is that not all of the headers are appearing in the body.

mike73

12:54 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



Problem solved:

I changed the new-lines to "\n" instead of "\r\n"

Strange, since the old system was Linux too, but whatever, now we all know.

Sekka

3:27 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



Very interesting ... I will try that later. Thank you.

mike73

3:33 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



I got this from one of the user comments in the PHP Help file. You should change the line breaks according to the server's OS.

Windows = "\r\n"
Mac = "\r"
Linux = "\n"

Sekka

3:51 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



So why did "\r\n" work on my old Linux server and your old Linux server?

jatar_k

5:57 pm on Jul 3, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



that was the exact problem I had, why, I don't know to be honest but that was the issue

mike73

6:14 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



So why did "\r\n" work on my old Linux server and your old Linux server?

I have no idea. Aren't computers great? ;-)

coopster

4:00 pm on Jul 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Ah yes, ye olde mail() and CRLF vs LF [webmasterworld.com] discussion. Plenty o' reading can be found in the links within that thread but the one thing you mentioned here is probably the best thing you can do ... set a variable at the top of your mail function scripts or site definitions/configurations for just this purpose and use that throughout your code. Much easier to change that in one spot as opposed to a find/replace in all your code. For example:
$crlf = "\r\n"; 
$headers = 'MIME-Version: 1.0' . $crlf;
$headers .= "From: $from" . $crlf;
$headers .= 'Content-type: text/html; charset=iso-8859-1' . $crlf;
... etc.

mike73

8:08 pm on Jul 5, 2006 (gmt 0)

10+ Year Member



Well, it seems like there is no universal solution. Now I'm getting quite a few returned mails due to "Disallowed characters found in MIME headers."

When I google it, it seems like some anti-virus programs don't like "\r\n" in the header, BUT I'M NOT USING THAT ANYMORE! I'm using "\n".

?

Sekka

8:19 am on Jul 6, 2006 (gmt 0)

10+ Year Member



Just send via SMTP. Solves all problems.

Love Sekka

mike73

8:32 am on Jul 6, 2006 (gmt 0)

10+ Year Member



Just send via SMTP. Solves all problems.

Can you reccomend some good, small code that just does the basics? I don't need to send attachments; I just want to send simple messages.

thanks!

Sekka

9:36 am on Jul 6, 2006 (gmt 0)

10+ Year Member



Unfortunately I don't know any good small codes. I use a pre-written script at the moment which I'm going to strip down at some point.

Google "PHPMailer" for the one I use.

mike73

12:42 pm on Jul 7, 2006 (gmt 0)

10+ Year Member



I'll give it a try. Thanks!

roleli

11:12 pm on Jul 20, 2006 (gmt 0)

10+ Year Member



Check if the new server is using qmail or sendmail..

sendmail I understand would change \r\n to \n while qmail does not seem to do that.

also another view...
From the php manual


Note: If messages are not received, try using a LF (\n) only. Some poor quality Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with RFC 2822.
from [php.net...]

in essence what happens is than \r\n is sometimess becomes \r\r\n

Please see [bugs.php.net...] for some discussion on the issue