title: IMAP - encoding UTF-8
body: <p>My script does not display Polish characters. How to fix it?
  Thank you.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;?php
          header('Content-Type: text/html; charset=utf-8');
  
          $hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
          $username = 'user@gmail.com';
          $password = 'pass';
  
          $inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());
  
  
          $emails = imap_search($inbox, 'ALL');
  
          if ($emails) {
              $output = '';
  
              foreach ($emails as $email_number) {
                  $overview = imap_fetch_overview($inbox, $email_number, 0);
                  $message = imap_fetchbody($inbox, $email_number, 2);
  
                  $output.= '&lt;div class="toggler ' . (imap_utf8($overview[0]-&gt;seen) ? 'read' : 'unread') . '"&gt;';
                  $output.= '&lt;span class="subject"&gt;' . imap_utf8($overview[0]-&gt;subject) . '&lt;/span&gt; ';
  
                  $output.= '&lt;span class="from"&gt;' . imap_utf8($overview[0]-&gt;from) . '&lt;/span&gt;';
                  $output.= '&lt;span class="date"&gt;on ' . imap_utf8($overview[0]-&gt;date) . '&lt;/span&gt;';
                  $output.= '&lt;/div&gt;';
  
                  /* output the email body */
                  $output.= '&lt;div class="body"&gt;' . imap_utf8($message) . '&lt;/div&gt;';
              }
  
              echo $output;
          }
          imap_close($inbox);
          ?&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Example output:</p>
  
  <blockquote>
    <p>Je=B6li chcesz uatrakcyjni=E6 wygl=B1d swojej skrzynki odbiorczej za
    pom= oc=B1</p>
  </blockquote>
  
  <p>I expect:</p>
  
  <blockquote>
    <p>Jeśli chcesz uatrakcyjnić wygląd swojej skrzynki odbiorczej za pomocą</p>
  </blockquote>