title: PHPMailer SMTP via Mailgun is Stripping HTML for Gmail, Yahoo and others
body: <p>I'm using PHPMailer via Mailgun (site is hosted via shared hosting on Hostgator.com) to send a validation email for users when they register. As the title, says, my HTML is being stripped in many of the common email providers. Any help with this issue would be MUCH appreciated—it's driving me nuts.</p>
  <p><strong>The email output (note the link is not there):</strong>
  <em>Thank you for registering with us. Please click the link below to verify your email address. Once verified, you will be able to login! Click this link to verify your email.
  Thank you!</em></p>
  <pre><code>define('VALIDATE_EMAIL_ENDPOINT', 'https://example.com/validate');
  
  
  if(sendEmail($email, $user['name'], 'Email Verification', 'Thank you for registering with us. Please click the link below to verify your email address. Once verified, you will be able to login!&lt;a href=&quot;' . VALIDATE_EMAIL_ENDPOINT . '/' . $requestID . '/' . urlSafeEncode($verifyCode). '&quot; /&gt;Click this link to verify your email&lt;/a&gt;&lt;br&gt;&lt;br&gt;Thank you!')) {
                                  return 0;
                              }
  </code></pre>
  <p>If it matters, this is urlSafeEncode’s function:</p>
  <pre><code>function urlSafeEncode($m) {
          return rtrim(strtr(base64_encode($m), '+/', '-_'), '=');
      }
  </code></pre>
  <p>The sendEmail function:</p>
  <pre><code>function sendEmail($to, $toName, $subj, $msg) { //function that sends email via PHPmailer 
          
          $mail = new PHPMailer(true);
          try {
          //Server settings
          //echo $to . $toName . $subj . $msg;
          $mail-&gt;isSMTP();
          $mail-&gt;Host       = SMTP_HOST;
          $mail-&gt;SMTPAuth   = true;
          $mail-&gt;Username   = SMTP_USERNAME;
          $mail-&gt;Password   = SMTP_PASSWORD;
          //$mail-&gt;SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
          $mail-&gt;SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //STARTTLS is for port 587
          $mail-&gt;Port       = SMTP_PORT;
  
          //Recipients
          $mail-&gt;setFrom(SMTP_FROM, SMTP_FROM_NAME);
          $mail-&gt;addAddress($to, $toName);
  
          // Content
          $mail-&gt;isHTML(true);
          $mail-&gt;Subject = $subj;
          $mail-&gt;Body    = $msg;
          $mail-&gt;SMTPDebug = 0; 
  
          $mail-&gt;send();
          return true;
          } 
          catch(Exception $e) {
              //echo '&lt;br&gt;&lt;br&gt;&lt;br&gt;Caught exception: ',  $e-&gt;getMessage(), &quot;\n&quot;;
              return false;
          }
      }
  </code></pre>
  <p>The original email appears to PASS SPF and DKIM:
  <a href="https://i.stack.imgur.com/2WjVG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2WjVG.png" alt="Original E-mail Top" /></a></p>
  <p><a href="https://i.stack.imgur.com/H8ICv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H8ICv.png" alt="Original E-mail Text" /></a></p>
  <p><strong>EDIT:</strong></p>
  <p><strong>This is the output in console from SMTPDebug = 2:</strong></p>
  <p><em>'2022-01-27 11:24:57 SERVER -&gt; CLIENT: 220 Mailgun Influx ready<br>\n2022-01-27 11:24:57 CLIENT -&gt; SERVER: EHLO example.com<br>\n2022-01-27 11:24:57 SERVER -&gt; CLIENT: 250-smtp-out-n01.prod.us-east-1.postgun.com250-AUTH PLAIN LOGIN250-SIZE 52428800250-8BITMIME250-SMTPUTF8250-PIPELINING250 STARTTLS<br>\n2022-01-27 11:24:57 CLIENT -&gt; SERVER: STARTTLS<br>\n2022-01-27 11:24:57 SERVER -&gt; CLIENT: 220 Go ahead<br>\n2022-01-27 11:24:57 CLIENT -&gt; SERVER: EHLO example.com<br>\n2022-01-27 11:24:57 SERVER -&gt; CLIENT: 250-smtp-out-n01.prod.us-east-1.postgun.com250-AUTH PLAIN LOGIN250-SIZE 52428800250-8BITMIME250-SMTPUTF8250 PIPELINING<br>\n2022-01-27 11:24:57 CLIENT -&gt; SERVER: AUTH LOGIN<br>\n2022-01-27 11:24:57 SERVER -&gt; CLIENT: 334 VXNlcm5hbWU6<br>\n2022-01-27 11:24:57 CLIENT -&gt; SERVER: [credentials hidden]<br>\n2022-01-27 11:24:57 SERVER -&gt; CLIENT: 334 UGFzc3dvcmQ6<br>\n2022-01-27 11:24:57 CLIENT -&gt; SERVER: [credentials hidden]<br>\n2022-01-27 11:24:58 SERVER -&gt; CLIENT: 235 Authentication successful<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: MAIL FROM:&lt;mail@ example.com&gt;<br>\n2022-01-27 11:24:58 SERVER -&gt; CLIENT: 250 Sender address accepted<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: RCPT TO:&lt; example @gmail.com&gt;<br>\n2022-01-27 11:24:58 SERVER -&gt; CLIENT: 250 Recipient address accepted<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: DATA<br>\n2022-01-27 11:24:58 SERVER -&gt; CLIENT: 354 Continue<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: Date: Thu, 27 Jan 2022 11:24:57 +0000<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: To: Fred Merc &lt; example @gmail.com&gt;<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: From: Support &lt;mail@ example.com&gt;<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: Subject: Email Verification<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: Message-ID: &lt;LxG6t46MyrcQEBfaez8ZSrY0VdYEXWkA1raYD9yIAH4@example.com&gt;<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: X-Mailer: PHPMailer 6.2.0 (<a href="https://github.com/PHPMailer/PHPMailer" rel="nofollow noreferrer">https://github.com/PHPMailer/PHPMailer</a>)<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: MIME-Version: 1.0<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: Content-Type: text/html; charset=iso-8859-1<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: <br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: Thank you for registering with us! Please click the link below to verify your email address. Once verified, you will be able to login!&lt;a href=&quot;https:// example.com/validate/59/qxKG_0cjpGUYjDeXNpBubBa5r1keLiM_OcA2LAsyoOE&quot; /&gt;Click this link to verify your email&lt;/a&gt;&lt;br&gt;&lt;br&gt;Thank you!<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: <br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: .<br>\n2022-01-27 11:24:58 SERVER -&gt; CLIENT: 250 Great success<br>\n2022-01-27 11:24:58 CLIENT -&gt; SERVER: QUIT<br>\n2022-01-27 11:24:58 SERVER -&gt; CLIENT: 221 See you later. Yours truly, Mailgun<br>\n[0]'</em></p>