title: imap_fetchbody() text/html section
body: <p>I'm trying to develop a E-Mail-Provider-Script.</p>
  
  <p>With the following function the E-Mails should be saved in the MySQL database directly, but my efforts to save only the <b>TEXT / HTML section</b> failed. What am I doing wrong( likely with <b>imap_fetchbody()</b> )?</p>
  
  <pre><code>function getEmailsImap($mailserver, $port, $user, $pass)
  {
  $imap = imap_open( "{" . $mailserver . ":" . $port . "}INBOX", $user, $pass );
  
      $check = imap_mailboxmsginfo($imap);
      $totalrows = imap_num_msg($imap);
      //iterate through all unread mails
      for ($index = 0; $index &lt; $totalrows; $index++)
      {
          $header = imap_header($imap, $index + 1);
           //get mail subject
          $subject = $header-&gt;subject;
           //get mail sent date
          $date = date(DateTime::ISO8601 , $header-&gt;udate);
          //get email authors
          $email = "{$header-&gt;from[0]-&gt;mailbox}@{$header-&gt;from[0]-&gt;host}";
          //get body
          $body = imap_fetchbody($imap, $index+1, "1.2"); /*** I think this might be the mistake **/
  
          //get user
          $to = $header-&gt;to[0]-&gt;mailbox;
          $user = explode("@", $to)[0];
  
          $id = (int)mysql_fetch_row(mysql_query("SELECT `id` FROM `fd_emails` ORDER BY `id` DESC LIMIT 1"))[0];
              $new_id = $id+1;
          $sql = mysql_query("INSERT INTO `fd_emails` (`id`, `subject`, `text`, `sender`, `user`, `date`)
                                                     VALUES ('$new_id', '$subject', '$body', '$email', '$user', '$date');");
  
          imap_delete($imap, $index + 1);
      }
      //close connection to mailbox
      imap_expunge($imap);
      imap_close($imap);
      return true;
   }
  </code></pre>
  
  <p>Many thanks in advance.</p>