Jump to content

HTML email showing <td width="xx"> code


Recommended Posts

This happens from time to time and it really drives me crazy.  I cannot get the problem to reproduce, although I have plenty of evidence that it is happening.  I have a php page that pulls in some database from mssql formats it in a nice table then send via email to a 3rd party.  All of that works great.  What happens is in some of the emails the first column will show the table cell information for the next column.  See example:

 

Mascaw	              Mar. 8, 2012 - 6:15 pm	          Ronnie Johnson
Newtown Pike<td width="150">       Mar. 8, 2012 - 6:15 pm 	          Todd Doe
Hall of Justice	      Mar. 8, 2012 - 6:15 pm	          Carol French

 

I had this problem before with another emailing system and found that wrapping the email to 900 before sending it out fixed it.  I wrapped this with $message = wordwrap($message, 900, "\n", true);  but it doesn't seem to make a difference.

 

Anyone ran into this before?  Any help would be greatly appreciated! Thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/256668-html-email-showing-code/
Share on other sites

$message = wordwrap($message, 900, "\n", true);

 

The "true" parameter forces the break at 900 (in this case). If this parameter is "false" it will find a space to break on. So, it could be breaking in the middle of a tag name or attribute name or value. (whitespace inside a tag is not significant unless it breaks a name or value)

 

The RFC specifies <CRLF> as the line break. Most mail systems probably handle <LF> alone, but there may be some that do not. You might consider wrapping it with "\r\n".

 

When generating HTML for a mail message (or for a web page, for that matter), I always stick in line-feeds at the end of blocks and so forth -- so, after </P>, </TR>, </DIV>, even </TD> if the rows are long), then I wordwrap() to about 70. wordwrap() seems to honor the line-feeds that are already present and just adds new ones (like for long paragraphs).

 

Other Considerations:

  • You really need to take a look at the source of the message -- either write it to a file or CC yourself on the email.
  • Find out what mail client is being used when this happens, is it always the same one or does this happen across multiple clients?
  • Is it possible that a value in a cell actually contains HTML special characters? Be sure to run the values through htmlspecialchars() or htmlentities() to prevent data from scrambling the page.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.