title: PHP, HTML, Email - Equals sign in email is being converted to different characters
body: <p><strong>The Setup...</strong></p>
  
  <p>I am sending an email via PHP, in the usual way...</p>
  
  <p><em>Code Block 0</em></p>
  
  <pre><code>mail('', $subject, $message, $headers);
  </code></pre>
  
  <p>... with the following content setup:</p>
  
  <p><em>Code Block 1</em></p>
  
  <pre><code>$boundary = uniqid('np');
  $message = '';
  
  $subject = 'Email Subject';
  
  $headers = "MIME-Version: 1.0\r\n";
  $headers .= "From: SURL &lt;noreply@someurl.com&gt;\r\n";
  $headers .= "To: ".$email."\r\n";
  
  $headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
  
  // Plain Text
  $message .= "Content-Type: text/plain; charset=utf-8\r\n";
  $message .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  
  $message .= 'Hi, you handsome SOB!!
               \n\n
               We have ...
               /n/n                
               And ...
               \n\n
               http://someurl.com/.../.../?a=' . $var1 . '&amp;b=' . $var2;
  
  $message .= "\r\n\r\n--" . $boundary . "\r\n";
  
  // HTML
  $message .= "Content-Type: text/html; charset=utf-8\r\n";
  $message .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
  
  $message .= '&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
              &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
              &lt;head&gt;
  
              &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  
              &lt;title&gt;Some Title&lt;/title&gt;
  
              &lt;style type="text/css"&gt;
                ... Lots of styles...
              &lt;/style&gt;
  
              &lt;/head&gt;
              &lt;body&gt;
  
              &lt;div class="message_container"&gt;
                &lt;div class="message_logo"&gt;&lt;/div&gt;
  
                &lt;div class="message_leading_line"&gt;
                  Hi, you handsome SOB!!
                &lt;/div&gt; &lt;!-- end message_leading_line --&gt;
  
                &lt;div class="message_top_content"&gt;
                  We have ...
                  &lt;br/&gt;
                  And ... 
                  &lt;a href="http://someurl.com/.../.../?a=' . $var1 . '&amp;b=' . $var2 . '" &gt;visit this link&lt;/a&gt;.
                &lt;/div&gt; &lt;!-- end message_top_content --&gt;
  
                &lt;div class="message_bottom_content"&gt;
                  If link doesn\'t work, copy and paste...
                  &lt;pre&gt;http://someurl.com/.../.../?a=' . $var1 . '&amp;b=' . $var2 . '&lt;/pre&gt;
                &lt;/div&gt; &lt;!-- end message_bottom_content --&gt;
  
              &lt;/div&gt; &lt;!-- end message_container --&gt;
  
              &lt;/body&gt;
              &lt;/html&gt;';
  
  $message .= "\r\n\r\n--" . $boundary . "--";
  </code></pre>
  
  <p>And this all works fine. The email sends without a hitch. Viewing the email, it is properly styled, and everything is where it should be - including all dynamically-added content.</p>
  
  <p><strong>Behavior Thus Far...</strong></p>
  
  <p>I've tried many test cases so far, and all have sent exactly as indented. Styling and all.</p>
  
  <p>One such successful case had:</p>
  
  <p><em>Code Blocks 3-1, 3-2</em></p>
  
  <pre><code>$var1 = '4pD9051LsVtQu96pLBH41019v28T0o4Z2I3U6urs';
  $var2 = 'verPkBE415i447V6R9o';
  </code></pre>
  
  <p>... so that the link in the email was:</p>
  
  <pre><code>http://someurl.com/.../.../?a=4pD9051LsVtQu96pLBH41019v28T0o4Z2I3U6urs&amp;b=verPkBE415i447V6R9o
  </code></pre>
  
  <p>The email sent properly, the links displayed properly, the links worked (clicking and copy/paste). Perfect!</p>
  
  <p><strong>The Issue...</strong></p>
  
  <p>for the most recent test:</p>
  
  <p><em>Code Blocks 4-1, 4-2</em></p>
  
  <pre><code>$var1 = '73jbzUN90j27ME5N6W4jh24o992V91m3R632Hlu0';
  $var2 = 'avr1owgJAAB3h4l1brw';
  </code></pre>
  
  <p>... so that the link was:</p>
  
  <pre><code>http://someurl.com/.../.../?a=73jbzUN90j27ME5N6W4jh24o992V91m3R632Hlu0&amp;b= avr1owgJAAB3h4l1brw
  </code></pre>
  
  <p>This time, the email sent... <em>properly</em>? It was sent with no obvious issues. At first glance, everything was as it should be. All the styling was as it should have been, all the content was where it needed to be.</p>
  
  <p><em>Note: The Gmail version displayed was the latter  version, with all of the markup removed and presented as plain text. Still the wrong URL was presented.</em></p>
  
  <p>But, upon closer inspection, the link <em>displayed in the email client</em> (Apple Mail and Gmail, both separate accounts) was:</p>
  
  <pre><code>http://someurl.com/.../.../?asjbzUN90j27ME5N6W4jh24o992V91m3R632Hlu0&amp;b=ver1owgJAAB3h4l1brw
  </code></pre>
  
  <p><em>The difference is immediately following the question mark.</em> What should be <code>?a=73jb</code> is instead <code>?asjb</code>. Clicking on the link doesn't work, nor does copying and pasting it. For obvious reasons - duh!</p>
  
  <p><strong>The Quirk...?</strong></p>
  
  <p>The odd thing is, if view the same email as source (View -> Message -> Raw Source), the links are exactly as they should be...</p>
  
  <p><em>Raw Source 1</em></p>
  
  <pre><code>To: 
  Subject: Email Subject
  X-PHP-Originating-Script: 2181:email.php
  MIME-Version: 1.0
  From:  SURL &lt;noreply@someurl.com&gt;
  To: email@email.com
  Content-Type: multipart/alternative;boundary=np57849efa2a13b
  X-Identified-User: {:box895.bluehost.com:...:...e.com} {sentby:program running on server}
  
  Content-Type: text/plain; charset=utf-8
  Content-Transfer-Encoding: 7bit
  
  Hi, you handsome SOB!!
  \n\n
  We have ...
  /n/n                 
  And ...
  \n\n
  http://someurl.com/.../.../?a=73jbzUN90j27ME5N6W4jh24o992V91m3R632Hlu0&amp;b=avr1owgJAAB3h4l1brw
  
  --np57849efa2a13b
  Content-Type: text/html; charset=utf-8
  Content-Transfer-Encoding: quoted-printable
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
  &lt;head&gt;
  
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  
  &lt;title&gt;Some Title&lt;/title&gt;
  
  &lt;style type="text/css"&gt;
  ... Lots of styles...
  &lt;/style&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  
    &lt;div class="message_container"&gt;
      &lt;div class="message_logo"&gt;&lt;/div&gt;
  
      &lt;div class="message_leading_line"&gt;
        Hi, you handsome SOB!!
      &lt;/div&gt; &lt;!-- end message_leading_line --&gt;
  
      &lt;div class="message_top_content"&gt;
        We have ...
        &lt;br/&gt;
        And ... 
        &lt;a href="http://someurl.com/.../.../?a=73jbzUN90j27ME5N6W4jh24o992V91m3R632Hlu0&amp;b=avr1owgJAAB3h4l1brw" &gt;visit this link&lt;/a&gt;.
      &lt;/div&gt; &lt;!-- end message_top_content --&gt;
  
      &lt;div class="message_bottom_content"&gt;
        If link doesn\'t work, copy and paste...
        &lt;pre&gt;http://someurl.com/.../.../?a=73jbzUN90j27ME5N6W4jh24o992V91m3R632Hlu0&amp;b=avr1owgJAAB3h4l1brw&lt;/pre&gt;
      &lt;/div&gt; &lt;!-- end message_bottom_content --&gt;
  
    &lt;/div&gt; &lt;!-- end message_container --&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  
  --np57849efa2a13b--
  </code></pre>
  
  <p>So what's going on? The data sent <em>appears</em> to be proper, but it is being displayed all cattywampus on very special cases. Why does <code>=73</code> convert to <code>s</code> (or, maybe <code>a=73</code> to <code>as</code>...)?</p>
  
  <p>I've checked <a href="http://ascii.cl" rel="nofollow">ASCII tables</a> and <a href="http://ascii.cl/htmlcodes.htm" rel="nofollow">HTML Codes</a>. In either case, the only thing associated with <code>73</code> is the capital letter "i".</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>Wouldn't you know that I'd stumble upon <a href="http://www.w3schools.com/tags/ref_urlencode.asp" rel="nofollow">This HTML URL Encoding Reference</a> immediately after posting this question.</p>
  
  <p>On there, you'll find <code>%73</code> associated with <code>s</code>.</p>
  
  <p>But, I'm still not quite sure how <code>=73...</code> is becoming <code>%73...</code> and then <code>s...</code>. Certainly seems something to do with the <code>utf-8</code>.</p>
  
  <p>Surely I'm not the first fellow to send an email, there must be a way...</p>
  
  <p><strong>EDIT 2 - SOLUTION!!</strong></p>
  
  <p>Solution and explanation got too long, so posted it as an answer.</p>