title: How to forward an email downloaded by PHP and IMAP?
body: <p>I'm writing a script to read email and distribute it to different email addresses depending on the TO address.  All email comes to one address, but I cannot seem to figure out how to forward an email, or create a new email and include all of the relevant message body.</p>
  
  <p>Right now I'm downloading the email using IMAP and using imap_fetchbody to get the email contents;</p>
  
  <pre><code>$email_body = imap_fetchbody($imapconnex, $msgnumber, 1);
  </code></pre>
  
  <p>Some email bodies don't display correctly, and others contain short lines with an <code>=</code> symbol at the end, causing the content to not display correctly. Also, I'm seeing random <code>A0</code> printed in my email bodies randomly.</p>
  
  <p>My plan was to use PHP's mail() function to send the email to where I want it to go and change the From address to the real From address. That would work for my needs, but I cannot seem to figure out how to retrieve the correct body, format it and send it.</p>
  
  <p>Here's my code that I'm using to send the email:</p>
  
  <pre><code>$header = imap_fetch_overview($imapconnex, $search[$i]);
  $email_subject = $header[0]-&gt;subject;
  $email_head = imap_fetchbody($imapconnex, $search[$i], 0); 
  $email_body = imap_fetchbody($imapconnex, $search[$i], 1); 
  mail("me@mydomain.com", $email_subject, $email_body, $email_head);
  </code></pre>
  
  <p>The headers seem to be forwarding fine, but the main body of the message is still displaying with <code>=</code> and <code>A0</code> symbols.</p>