title: php - imap_fetchbody message is encoded
body: <p>I'm building a web app where users will be able to see emails sent to their account. I am having some issues regarding the encoding of their messages.</p>
  
  <p>As a test, I just received a registration email from a website. The mail contained HTML.</p>
  
  <p>It should look like this:</p>
  
  <pre>Thanks for signing up to Virally, we're excited to have you using our product!  
    Start Capturing Leads with Virally!  
    Click here to make your first campaign &gt;&gt;  
    You'll need a digital reward to create a campaign, like an eBook, Whitepaper, Video, free book chapter, Podcast etc. (We can help with this if you don't have anything of your own, just ask)  
    Please hit reply to this email if you'd like some help getting started.   
  Thanks,  
   Liam Gooding  liam@virallyapp.com  Virally Co-founder    </pre>
  
  <p>That is how it looks in my inbox; although, on my website it looks like this:</p>
  
  <pre>VGhhbmtzIGZvciBzaWduaW5nIHVwIHRvIFZpcmFsbHksIHdlJ3JlIGV4Y2l0ZWQgdG8gaGF2ZSB5
  b3UgdXNpbmcgb3VyIHByb2R1Y3QhwqAgCiAgU3RhcnQgQ2FwdHVyaW5nIExlYWRzIHdpdGggVmly
  YWxseSEgIAogIENsaWNrIGhlcmUgdG8gbWFrZSB5b3VyIGZpcnN0IGNhbXBhaWduICZndDsmZ3Q7
  ICAKICBZb3UnbGwgbmVlZCBhIGRpZ2l0YWwgcmV3YXJkIHRvIGNyZWF0ZSBhIGNhbXBhaWduLCBs
  aWtlIGFuIGVCb29rLCBXaGl0ZXBhcGVyLCBWaWRlbywgZnJlZSBib29rIGNoYXB0ZXIsIFBvZGNh
  c3QgZXRjLiAoV2UgY2FuIGhlbHAgd2l0aCB0aGlzIGlmIHlvdSBkb24ndCBoYXZlIGFueXRoaW5n
  IG9mIHlvdXIgb3duLCBqdXN0IGFzaykgIAogIFBsZWFzZSBoaXQgcmVwbHkgdG8gdGhpcyBlbWFp
  bCBpZiB5b3UnZCBsaWtlIHNvbWUgaGVscCBnZXR0aW5nIHN0YXJ0ZWQuICAgClRoYW5rcywgIAog
  TGlhbSBHb29kaW5nICBsaWFtQHZpcmFsbHlhcHAuY29tICBWaXJhbGx5IENvLWZvdW5kZXIgICAg</pre>
  
  <p>This is my PHP code:</p>
  
  <pre><code>$openmail = imap_open($dns,$email,$password ) or die("Cannot Connect ".imap_last_error());
  
  if ($openmail) {
    echo  "&lt;div class='noti success'&gt;You have ".imap_num_msg($openmail). " messages in your inbox&lt;/div&gt;\n\r";
    $tot=imap_num_msg($openmail);
    for($i=$tot;$i&gt;0;$i--) {
  
      $header = imap_header($openmail,$i);
      echo "&lt;br&gt;";
      echo $header-&gt;Subject." (".$header-&gt;Date.")";
      $body = imap_fetchbody($openmail, $i,'1');
  
      echo "&lt;div class='faq-tile'&gt;$body&lt;/div&gt;";
    }
    imap_close($openmail);
  }
  </code></pre>
  
  <p>The <code>$body</code> variable, is the one printing out the body of the mail.</p>