jebbie jebbie - 1 year ago 50
PHP Question

HTML-Email annoying line-breaking

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: <

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:

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... :/

Answer Source

Simple workaround

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

Every HTML tag will start from new line giving you:


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?)