Friday, May 6, 2011

WARNING About HTML Email

I have a number of Web forms that return emails via PHP scripts. In the case of an ecommerce site, the script puts the details of the order into an HTML table that the client can print out nicely.

A problem arose when orders came in with randomly placed bang (exclamation mark !) characters in the latter part of the message. I could never duplicate the problem, nor could I find a definitive explanation for it.

Today, I Googled the problem yet again, getting back an explanation in the first return.

It turns out that an email transmission cannot have a line exceeding 998 characters without a line break. My table quickly filled up that quota with <tr><td> kinds of things, until, when the table got down to the end (the part where I was having the problem), it had exceeded the 998 characters.

To solve the problem, I put a \n character somewhere in the middle of the string that creates the table. Of course, the HTML parser ignores this line break, but it apparently satisfies the email specification.

Orders are now coming in  without the random bang characters.

0 comments: