title: php imap - get body and make plain text
body: <p>I am using the PHP imap function to get emails from a POP3 mailbox and insert the data into a MySQL database.</p>
  
  <p>Here is the PHP code:</p>
  
  <pre><code>$inbox = imap_open($hostname,$username,$password) or die('Cannot connect: ' . imap_last_error());
  
  $emails = imap_search($inbox,'ALL');
  
  
  if($emails)
  {
      $output = '';
  
      rsort($emails);
  
      foreach($emails as $email_number) 
      {
          $header=imap_headerinfo($inbox,$email_number);
  
          $from = $header-&gt;from[0]-&gt;mailbox . "@" . $header-&gt;from[0]-&gt;host;
          $toaddress=$header-&gt;toaddress;
          $replyto=$header-&gt;reply_to[0]-&gt;mailbox."@".$header-&gt;reply_to[0]-&gt;host;
          $datetime=date("Y-m-d H:i:s",$header-&gt;udate);
          $subject=$header-&gt;subject;
  
          //remove the " from the $toaddress
          $toaddress = str_replace('"','',$toaddress);
  
          echo '&lt;strong&gt;To:&lt;/strong&gt; '.$toaddress.'&lt;br&gt;';
          echo '&lt;strong&gt;From:&lt;/strong&gt; '.$from.'&lt;br&gt;';
          echo '&lt;strong&gt;Subject:&lt;/strong&gt; '.$subject.'&lt;br&gt;';
  
          //get message body
          $message = (imap_fetchbody($inbox,$email_number,1.1)); 
          if($message == '')
          {
              $message = (imap_fetchbody($inbox,$email_number,1));
          }
  }
  </code></pre>
  
  <p>It works fine, however on some emails in the body I get <code>=</code> in between words, or <code>=20</code> in between words. And other times the emails will just be blank even though they are not blank when sent.</p>
  
  <p>This only happens when coming from certain emails.</p>
  
  <p>How can I get round this and just make the email completely plain text?</p>