11

I'm digging deep in html-email stuff and finally, i have still an unsolved problem with annoying line-breaks :/

GMail and or Outlook are often breaking the line exactly during a tag - resulting in a completely broken look & feel.. so it can happen that the whole content is in a < h2 > because the ending-tag is broken through a line-break..

m</strong><br/>Passwort: <
strong>20o3a7

That's an example of a broken e-mail generated by my PHPMailer code..

Now i was fascinated with an email of a company, perfectly styled newsletter.. There i saw a code like this:

<table width=3D"100%" cellspacin=
g=3D"0" border=3D"0" cellpadding=3D"0">

This i can see on almost any line of this strange e-mail -> always ending with "=" on any line, altough if it is in the middle of a tag or a parameter-word.. and it is perfectly working! How that? It seems to me that this line-breaks are generated before it comes to the e-mail client, but this is only speculation of me...

I can find extermely nice articles how to create a correct HTML-Email like this:

http://24ways.org/2009/rock-solid-html-emails

But nobody writes something about this annoying line-break problem, but i can't believe that i'm the only one that has this issue... :/

jebbie
  • 1,418
  • 3
  • 17
  • 27
  • 2
    As a note, this happens when a line of HTML is considered too long for the email and the mail server breaks the line anywhere. – Alexis Wilke Dec 06 '13 at 08:01

3 Answers3

13

Simple workaround

$body = str_replace("<","\r\n<", $body);

Every HTML tag will start from new line giving you:

m
</strong>
<br/>Passwort: 
<strong>20o3a7

Another thing is, i used PHPMailer in many projects, sending thousands e-mails to all mail clients, and i never experienced that issue. Make sure your code is OK. (maybe your text editor is wrapping that lines?)

Peter
  • 16,453
  • 8
  • 51
  • 77
  • Woaaa you made my day :)) You're simple workaround is working like a charm -> immediately i have no broken mails anymore ind Outlook and GMail... Just another thing i'm wondering... Do you have an idea why Outlook is deleting my "background: url(an-image-url.jpg)" inline-style-definition on a table-layout's TD element? Any other tested client is rendering perfectly my background-image-styling, but not outlook... – jebbie Aug 31 '12 at 14:07
  • what about [this](http://stackoverflow.com/questions/1124149/is-embedding-background-image-data-into-css-as-base64-good-or-bad-practice) – Peter Aug 31 '12 at 14:28
  • 3
    Note that the =3D in an encoded email represents the character '=' (3D is the ASCII code in hex.) – Alexis Wilke Dec 06 '13 at 07:59
  • 1
    Emails shouldn't have more than 70 chars per line for comapitibility reasons. This is why that = line breaking thingy is used. Your code won't work on all email clients if html tags become longer than those 70 characters. – Manuel Arwed Schmidt Mar 02 '15 at 19:10
  • @ManuelArwedSchmidt you are right, I removed wrong part – Peter Mar 03 '15 at 11:41
3

<table width=3D"100%" cellspacing=3D"0" border=3D"0" cellpadding=

It's called quoted printable encoding which is common for html emails. '=3D' for instance stands for '='.

Regarding to your problem: never occured to me. It's be difficult to debug without beeing able to look at the source. But it seems you got a solution anyway. :)

lukeA
  • 53,097
  • 5
  • 97
  • 100
0
$message = imap_fetchbody($inbox,$id,2);
$message = quoted_printable_decode($message); // magic
Patrioticcow
  • 26,422
  • 75
  • 217
  • 337