How to preserve HTML code when sending it with PHPMailer as an EMail
<p>I am trying to send a HTML mail (and a fallback plain text one) with <code>PHPMailer</code>. My problem is, that when I receive the e-mail, the HTML code gets all mengled up, because of the line-breaks that are added to it.</p>

<p>I've tried changing the encoding from <code>quoted-printable</code>, to either <code>8bit</code> or <code>7bit</code>, but PHPMailer just simply reverts to <code>quoted-printable</code> every time.</p>

<p>I've managed to find the cause of this in this answer: <a href="https://stackoverflow.com/a/33102397/2691879">https://stackoverflow.com/a/33102397/2691879</a></p>

<p>Basically, it looks like, that adding a line break after every 998 characters, is a must when sending e-mails, but my question is, how can I be assured, that the HTML code is preserved while sending e-mails then?</p>

<p>Am I missing something here?</p>

<p>Unfortunatly, adding the line breaks manually to the template I use, is out of the question, because the intended use of this code, is that the clients of the site would be able to create their own templates to be sent, and also, there are some variable data in the template, that get's replaced before sending.</p>

<p>Here's some code:</p>

<pre><code>self::$Mailer-&gt;addAddress($to);
self::$Mailer-&gt;Subject=$subject;
self::$Mailer-&gt;Body=$template['html'];
self::$Mailer-&gt;AltBody=$template['text'];
self::$Mailer-&gt;CharSet = 'UTF-8';
self::$Mailer-&gt;Encoding = '7bit';
self::$Mailer-&gt;send();
</code></pre>

<p>The HTML template that I use, is the following:</p>

<pre><code>&lt;h2&gt; Thank you for joining %PORTALNAME &lt;h2&gt;&lt;span style='font-size:14px; font-weight: normal;'&gt; You are receiving this e-mail because you (hopefully) created a new member account at %PORTALNAME! In order to be able to fully use your account, you will need to confirm your e-mail address, by clicking on %CONFIRMATIONLINK.&lt;br&gt; If your e-mail client doesn't recognize the above link, you can copy this url &lt;b&gt;%JUSTLINK&lt;/b&gt; and paste it in any browser window, to confirm your account. &lt;br&gt;&lt;br&gt; If it wasn't you, who opted for this registration, please ignore this message!&lt;/span&gt; &lt;br&gt; &lt;h3 style='margin-bottom: 5px;'&gt; Your login credentials: &lt;/h3&gt;&lt;div style='width: 100px; float: left;'&gt; Username: &lt;/div&gt;&lt;div style='float: left;'&gt; %EMAIL &lt;/div&gt;&lt;div style='clear:both;'&gt;&lt;/div&gt;&lt;div style='width: 100px; float: left;'&gt; Password: &lt;/div&gt;&lt;div style='float: left;'&gt; %PLAINPASSWORD &lt;/div&gt;&lt;div style='clear:both;'&gt;&lt;/div&gt;
</code></pre>

<p>And the source of the message that I receive looks like this:</p>

<pre><code>Return-Path: &lt;xxx@xxx.xxx&gt;
Delivered-To: xxx@xxx.xxx
Received: from xxx.xxx.xxx
    by xxx.xxx.xxx (Dovecot) with LMTP id wT5IIgnOKVh8fgAAhsLUGA
    for &lt;xxx@xxx.xxx&gt;; Mon, 14 Nov 2016 14:45:29 +0000
Return-path: &lt;xxx@xxx.xxx&gt;
Envelope-to: xxx@xxx.xxx
Delivery-date: Mon, 14 Nov 2016 14:45:29 +0000
Received: from xxx.xxx.xxx ([199.191.58.218]:48854)
    by xxx.xxx.xxx with esmtp (Exim 4.87)
    (envelope-from &lt;xxx@xxx.xxx&gt;)
    id 1c6IVl-0008M6-Bo
    for xxx@xxx.xxx; Mon, 14 Nov 2016 14:45:29 +0000
Received: by xxx.xxx.xxx (Postfix, from userid 48)
    id 7071DAA810F7; Mon, 14 Nov 2016 09:44:49 -0500 (EST)
To: xxx@xxx.xxx
Subject: Account confirmation
X-PHP-Originating-Script: 505:PHPMailer.php
Date: Mon, 14 Nov 2016 16:44:49 +0200
From: PortalName - Account Information &lt;xxx@xxx.xxx&gt;
Message-ID: &lt;f2eb3096b55450ad7725097793b72ba9@PortalName.agentventure.com&gt;
X-Mailer: PHPMailer 5.2.14 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

&lt;h2&gt; Thank you for joining PortalName &lt;h2&gt;&lt;span style=3D'font-size:14px; font-w=

eight: normal;'&gt; You are receiving this e-mail because you (hopefully) crea=

ted a new member account at PortalName! In order to be able to fully use your a=

ccount, you will need to confirm your e-mail address, by clicking on &lt;a hre=

f=3D'xxx.xxx.xxx/verify-account/xxxxxx/'&gt; this link&lt;/a&gt;.&lt;br&gt; I=

f your e-mail client doesn't recognize the above link, you can copy this ur=

l &lt;b&gt;xxx.xxx.xxx/verify-account/xxxxxx/&lt;/b&gt; and paste it in an=

y browser window, to confirm your account. &lt;br&gt;&lt;br&gt; If it wasn't you, who o=

pted for this registration, please ignore this message!&lt;/span&gt; &lt;br&gt; &lt;h3 sty=

le=3D'margin-bottom: 5px;'&gt; Your login credentials: &lt;/h3&gt;&lt;div style=3D'widt=

h: 100px; float: left;'&gt; Username: &lt;/div&gt;&lt;div style=3D'float: left;'&gt; xxx.=

xxx@xxx.xxx &lt;/div&gt;&lt;div style=3D'clear:both;'&gt;&lt;/div&gt;&lt;div style=

=3D'width: 100px; float: left;'&gt; Password: &lt;/div&gt;&lt;div style=3D'float: left;=

'&gt; xxxxxxxxx &lt;/div&gt;&lt;div style=3D'clear:both;'&gt;&lt;/div&gt;
</code></pre>