Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMailer inserts '=' equal sign every 75th character

Tags:

php

phpmailer

Using PHPMailer 5.2.14, emails are sent in text/html. The outgoing text is littered with equal signs every 75th character.

I tried using the EOL workaround, but it did not remove the extra equal signs:

$email = new PHPMailer();
$email->From      = '[email protected]';
$email->FromName  = 'FromUser';
$email->AddAddress( '[email protected]' );
$email->Subject   = 'This is a test';
$email->IsHTML(true);
$email->Body = "<p>This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; </p>";

// fix EOL here? 
$email->LE = PHP_EOL;

$email->Send();

Resulting source upon receipt:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><font face="arial"><base href="http://example.com/"><!-- </base> -->=
<p>This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This i=
s a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.=
&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; Th=
is is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a t=
est.&nbsp; This is a test.&nbsp; This is a test.&nbsp; This is a test.&nbsp;=
 </p></font>

The equal signs appear when viewing in Outlook. When I send the same text/html to a gmail account, the equal signs are not present.

What needs to happen to eliminate these stray equal signs for recipients using Outlook?

like image 532
a coder Avatar asked Nov 18 '15 18:11

a coder


4 Answers

I had the same problem with html-emails in PHPMailer. I've tested different things and found out:

  • The problem happens if the message has a special length - in my case >1002 letters in one line (when I have removed some letters (irrelevant which ones) the email was correct)
  • The problem is visible only in some email-programms (e.g. MS Outlook, website t-online.de; no problems with yahoo)
  • I've testet PHPMailer 5.2.7 - 5.2.14: The problem exists in PHPMailer >5.2.10 (no problems in PHPMailer 5.2.7 - 5.2.10)
  • Solutions like '$mail->Encoding = "7bit";' or '$mail->LE = PHP_EOL;' didn't worked for me
  • No Problems when sending the email via isSmtp().
  • Tested on two different servers: Server 1 contains equal signs, Server 2 doesn't contain that signs but has wrong linebreaks - the php-configuration on both servers is nearly identical > it doesn't seem to be a php-problem

So for me the solution was "take PHPMailer 5.2.10" till they solve the problem in a newer version - No good solution, but it works for me till I find a better one ;-)

like image 182
SusiMage Avatar answered Nov 16 '22 09:11

SusiMage


This is known as quoted-printable encoding and is quite common in email messages. The equal sign is used as an escape character, and line lengths are limited to 76 characters. If Outlook is not recognizing this, you may have to manually set headers telling it that it's encoded in this fashion.

like image 26
miken32 Avatar answered Nov 16 '22 10:11

miken32


Here's what your document should look like:

<!DOCTYPE html>
<head>
   meta stuff and <base href...>
</head>
    <body>
    HTML stuff
    </body>
</html>

Anything outside that and not conforming to HTML, will put a damper on your day.

Far as I can see, you have meta that belong in <head> and have <font> tags that belongs in <body> etc. etc. If there isn't proper HTML document structuring, then something will complain for sure. Including a valid doctype.

A quick sidenote about the <font> tag; it's in deprecation.

You could use inline CSS styling instead. Do not use <style> tags as most Email clients will throw that out and ignore it.

like image 39
Funk Forty Niner Avatar answered Nov 16 '22 10:11

Funk Forty Niner


With '$mail->Encoding = 'base64'; it works for us now with v5.2.17. Hopefully this is finally fixed in v6.

like image 2
asdfklgash Avatar answered Nov 16 '22 09:11

asdfklgash