PDA

View Full Version : Format of message sent via ezmlm


JMT
04-07-2001, 02:35 PM
I have a page within my site that allows my privileged users to compose a message and then send it to a mail list for distribution. The process works fine with one problem.

When Outlook users receive the mail, all lines are concatenated together unless two newlines are included in which case a blank line is inserted. The same message appears just fine. To clarify:

Original message:
Line 1
Line 2
Line 3

Outlook displays:
Line 1 Line 2 Line 3

Hotmail displays:
Line 1
Line 2
Line 3

If I send the message through the CNC it works fine in both Outlook and Hotmail.

Thanks

janderk
04-07-2001, 02:45 PM
Seems like you have a carriage return / line feed problem.

To go to the next line, Windows uses a carriage return (Ascii char 13) and a Line Feed (Ascii char 10).

Unix only uses a line feed and to make it even more fun Apple uses only a carriage return.

JMT
04-07-2001, 02:56 PM
Thats what I thought but when I added code to replace the newlines with a newline and carriage return it worked in Outlook but double spaced Hotmail.

So then I just replaced the newlines with carriage returns. Appeared the same as just newlines which was the original problem.

sheila
04-07-2001, 04:59 PM
What script are you using?

I also have a page on my site that lets users do the same thing, but have had no reports from others that it comes out looking screwy in anyone's mail reader.

I think that it is important that you are using something equivalent to the <pre></pre> tags used in HTML. In other words, mark it as formatted text to be displayed exactly as typed.

JMT
04-08-2001, 12:04 AM
I use a simple php script. First pass it puts up a form with a text field for subject and a textarea for the message.

Second pass it uses the mail command to send the message to the mail list as the owner. That is a simplification but its not a complicated script.

JMT
04-08-2001, 01:32 AM
OK - I dumped out both messages. The one from CNC and from my script. Looking through them the only difference I could see was that the CNC version had a header &quot;X-Mailer: FQ::CNC::ezMLM&quot;. Other then that I couldn't see any difference. I tried adding that header in the PHP mail command but that didn't seem to help.

Looking through the forums for &quot;X-Mailer&quot; I did come across a posting that said if a \r was used in the header then it had to be used in the body also. I rechecked both messages and neither had a \r but just to be sure I changed my script to replace all \n with \n\r.

Now my output looks fine in Outlook but in Hotmail it is double spaced. Its getting late, the frustration factor is high so I will hang it up for now. Any ideas would be appreciated.

janderk
04-08-2001, 08:00 AM
Thats what I thought but when I added code to replace the newlines with a newline and carriage return it worked in Outlook but double spaced Hotmail.
Be carefull. It should be a carriage return first and then a line feed character. Not the other way around.

You could also check the email message source. It should contain something like

Content-Type: text/plain; charset=&quot;iso-8859-1&quot;

Jan Derk

Justin
04-09-2001, 12:56 PM
This problem plagued me for a while. Outlook will simply not show line returns, and Eudora (some versions) will double the last character on each line.

The solution? Strip carriage returns. Sound odd? Well, the POP protocol specifies Unix-style line endings, where HTTP post operations (eg, filling out a form) will send whatever the client is using.

Outlook for some reason chokes when carriage returns are present in an email -- even though they are standard Windows line endings, they are not standard POP mail line endings and thus it doesn't handle them correctly in that situation.

When stripping carriage returns, though, care must be taken - Mac users will send *only* a CR, with no LF, so stripping CRs will cause problems there.

The solution in PHP is rather simple. Do two replaces:
</font><font face="Courier" size="3">
$text = str_replace (&quot;\r\n&quot;, &quot;\n&quot;, $text);
$text = str_replace (&quot;\r&quot;, &quot;\n&quot;, $text);
</font><font face="Verdana, Arial" size="2">
First, replace any CRLF with LF, then if there are any CRs left, it must be a Mac -- so replace those as well. Note that a regex isn't necessary since you're matching an exact string.

Hope this helps.

<EDIT>
Hopefully this won't add any confusion, but keep in mind that \n does not mean LF -- it means newline. A newline is system-dependant, and on Unix it does mean LF. But it is common for people to use \n in place of LF, when in fact on Windows, a \n translates into CRLF (thus the above pattern wouldn't match).

The proper way to designate an LF is with a \f, and this will work on any platform.

So we have:</font><font face="Courier" size="3">
[nbsp][nbsp][nbsp][nbsp]Windows[nbsp][nbsp]Unix[nbsp][nbsp] Mac
\n[nbsp][nbsp]CRLF[nbsp][nbsp][nbsp][nbsp] LF[nbsp][nbsp][nbsp][nbsp] CR
\f[nbsp][nbsp]LF[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp] LF[nbsp][nbsp][nbsp][nbsp] LF
\r[nbsp][nbsp]CR[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp] CR[nbsp][nbsp][nbsp][nbsp] CR
</font><font face="Verdana, Arial" size="2">
Finally, note that Sendmail strips CRs automatically, but Qmail does not. Sendmail tries to be smart, but it should send the mail as it is received without modifying it, as Qmail does.
</EDIT>

------------------
Justin Nelson
SFE Software (http://www.sfesoftware.com)
[This message has been edited by Justin (edited 04-09-01@12:02 pm)]

JMT
04-09-2001, 06:28 PM
Works great. Thank you.