tags:

views:

40

answers:

2

Hi all,

Been having this problem for very long and couldn't find any solution. What happen is that occasionally the email that I sent out has the header appearing in the body text. On closer examination, the first line of the header was read as header but the rest of the header are thought to be body. It only happens to a selected few recipients so I'm wondering whether it's their mail client that's unable to read the headers correctly.

A copy and paste of a sample corrupted mail (it appears as plain text in the mail):

Content-Type: multipart/alternative;boundary="4ca471aa8aed6" From: XXX <[email protected]> Message-ID: <[email protected]> X-Mailer: PHP v5.2.14
Date: Thu, 30 Sep 2010 12:16:58 +0100 (BST)
X-Spam: [F=0.2000000000; B=0.500(0); STSI=0.500(-24); STSM=0.500(-24); CM=0.500; MH=0.500(2010093005); S=0.200(2010073001); SC=none]
X-MAIL-FROM: <[email protected]>
X-SOURCE-IP: [83.138.141.236]
X-AnalysisOut: [v=1.0 c=1 a=x7AK10Bnz50A:10 a=BLceEmwcHowA:10 a=VqisAvswpt]
X-AnalysisOut: [4FyOtI4ClGvg==:17 a=vw80RhgAwbNm-Xx5EKgA:9 a=dX3ThSBsV1pHv]
X-AnalysisOut: [tqXy1oA:7 a=yEJHB1MS_eYZD3xBjjsxBp4tBv8A:4 a=QEXdDO2ut3YA:]
X-AnalysisOut: [10 a=xNwWcUBMj4F1506d:21 a=jABlWf4rlI1j5d6A:21 a=MGaB5ybbA]
X-AnalysisOut: [AAA:8 a=6-7fRTDBl2X58nfIeBAA:9 a=UMAsvBM9vilmjbwRO0EA:7 a=]
X-AnalysisOut: [TNgMOtyArbXF74fBhVb4Pk7RMrwA:4 a=_wpYbfnAMgAA:10 a=iDrULPt]
X-AnalysisOut: [N55ecZwpH:21 a=e4HzzWUux0m5Q-ha:21]

--4ca471aa8aed6 Content-type: text/plain; charset=utf-8

Mail body here onwards..

The corresponding php coding of the above mail is:

$eol = "\r\n";
$boundary = uniqid();
$headers  = 'MIME-Version: 1.0' . $eol;
$headers .= 'Content-Type: multipart/alternative;boundary="' . $boundary . '"' . $eol;
$headers .= "From: $firstname $lastname <$email>" .$eol;
$headers .= 'Message-ID: <'.time().'[email protected]>'.$eol.
  'X-Mailer: PHP v' . phpversion() . $eol;


$subject = "Subject";
$message = "--$boundary$eol";
$message .= "Content-type: text/plain; charset=utf-8$eol$eol;
$message .="Message body here";

Notice that the first line in the header does not appear in the email. Anybody experience it before? It only happens to a few recipients, 99% of the mails are fine. For those that have this problem, they mentioned that they are fine receiving HTML mails from other sources. Also, I know one of them is using IBM lotus notes.. any issues there?

Thanks!

A: 

I think it's due to your line break which is used on windows servers for hotmail, live and msn. For other mail servers you have to use "\n".

MatTheCat
A: 

EOLs in headers can be preprocessed by your local PHP/mail functions. E.g. if you are running the system on Windows, \r\n can sometimes be re-converted to \r\r\n, as the software is expecting to receive "native-style" \n and change it to "internet-style" \r\n.

Afterward, depending on the receiving side's mail server/mail client, these "\r\r\n" can be understood as double newline, causing your problem.

Solution: use your 'local' newline style for headers, e.g. \n on Windows and \r\n on UNIX.

forgot to mention: there is a PHP_EOL constant in PHP which should be used in this case.

Levon Mirzoyan
I know I'm running on LINUX, so \r\n should be valid. It works for most people. Only a handful couldn't read the header properly.. The PHP_EOL constant for my machine should also be \r\n?
zxiank