Не удается получить содержимое обычной текстовой почты с помощью протокола IMAP

Я читаю письма с определенного идентификатора почты, используя функцию IMAP я не могу читать содержимое почты для plain text сообщений. Он отлично подходит для HTML Mails . После запуска кода все plain text сообщения остаются такими же непрочитанными и html-сообщениями, которые помечены как прочитанные, и другие вещи, такие как идентификатор почтового отправителя и тема, которую я могу прочитать. Только проблема заключается в чтении содержимого. Вот код, который я пробовал

  include('imap.php'); $hostname = '{xxx.org:143/novalidate-cert}INBOX'; $username = 'xxx-xxx@xx.org'; $password = 'xxxxx'; $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to : ' . imap_last_error()); $emails = imap_search($inbox,'UNSEEN'); if($emails) { $output = ''; rsort($emails); foreach($emails as $email_number) { $structure = imap_fetchstructure($inbox, $email_number); $savedir = dirname(__FILE__).'/uploads/'; $attachments = array(); if(isset($structure->parts) && count($structure->parts)) { for($i = 0; $i < count($structure->parts); $i++) { $attachments[$i] = array( 'is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '' ); if($structure->parts[$i]->ifdparameters) { foreach($structure->parts[$i]->dparameters as $object) { if(strtolower($object->attribute) == 'filename') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['filename'] = $object->value; } } } if($structure->parts[$i]->ifparameters) { foreach($structure->parts[$i]->parameters as $object) { if(strtolower($object->attribute) == 'name') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['name'] = $object->value; } } } if($attachments[$i]['is_attachment']) { $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1); if($structure->parts[$i]->encoding == 3) { // 3 = BASE64 $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); } elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); } $savepath = $savedir . $attachments[$i]['filename']; file_put_contents($savepath, $attachments[$i]['attachment']); } } } $name = $structure->parts[1]->dparameters[0]->value; $overview = imap_fetch_overview($inbox,$email_number,0); $msg = imap_fetchbody($inbox,$email_number,1.2); $message=''; if($msg=='') { $message = imap_fetchbody($inbox,$email_number,2.0); }else{ $message=$msg; } $sub=$overview[0]->subject; $from=$overview[0]->from; $arr = explode('<', $from); $from_mail = $arr[1]; if($from_mail!='') { $from=str_replace('>','',$from_mail); } $randstr=''; srand((double)microtime()*1000000); $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; while(strlen($randstr)<5) { $randstr.=substr($chars,(rand()%(strlen($chars))),1); } в  include('imap.php'); $hostname = '{xxx.org:143/novalidate-cert}INBOX'; $username = 'xxx-xxx@xx.org'; $password = 'xxxxx'; $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to : ' . imap_last_error()); $emails = imap_search($inbox,'UNSEEN'); if($emails) { $output = ''; rsort($emails); foreach($emails as $email_number) { $structure = imap_fetchstructure($inbox, $email_number); $savedir = dirname(__FILE__).'/uploads/'; $attachments = array(); if(isset($structure->parts) && count($structure->parts)) { for($i = 0; $i < count($structure->parts); $i++) { $attachments[$i] = array( 'is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '' ); if($structure->parts[$i]->ifdparameters) { foreach($structure->parts[$i]->dparameters as $object) { if(strtolower($object->attribute) == 'filename') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['filename'] = $object->value; } } } if($structure->parts[$i]->ifparameters) { foreach($structure->parts[$i]->parameters as $object) { if(strtolower($object->attribute) == 'name') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['name'] = $object->value; } } } if($attachments[$i]['is_attachment']) { $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1); if($structure->parts[$i]->encoding == 3) { // 3 = BASE64 $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); } elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); } $savepath = $savedir . $attachments[$i]['filename']; file_put_contents($savepath, $attachments[$i]['attachment']); } } } $name = $structure->parts[1]->dparameters[0]->value; $overview = imap_fetch_overview($inbox,$email_number,0); $msg = imap_fetchbody($inbox,$email_number,1.2); $message=''; if($msg=='') { $message = imap_fetchbody($inbox,$email_number,2.0); }else{ $message=$msg; } $sub=$overview[0]->subject; $from=$overview[0]->from; $arr = explode('<', $from); $from_mail = $arr[1]; if($from_mail!='') { $from=str_replace('>','',$from_mail); } $randstr=''; srand((double)microtime()*1000000); $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; while(strlen($randstr)<5) { $randstr.=substr($chars,(rand()%(strlen($chars))),1); } к  include('imap.php'); $hostname = '{xxx.org:143/novalidate-cert}INBOX'; $username = 'xxx-xxx@xx.org'; $password = 'xxxxx'; $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to : ' . imap_last_error()); $emails = imap_search($inbox,'UNSEEN'); if($emails) { $output = ''; rsort($emails); foreach($emails as $email_number) { $structure = imap_fetchstructure($inbox, $email_number); $savedir = dirname(__FILE__).'/uploads/'; $attachments = array(); if(isset($structure->parts) && count($structure->parts)) { for($i = 0; $i < count($structure->parts); $i++) { $attachments[$i] = array( 'is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '' ); if($structure->parts[$i]->ifdparameters) { foreach($structure->parts[$i]->dparameters as $object) { if(strtolower($object->attribute) == 'filename') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['filename'] = $object->value; } } } if($structure->parts[$i]->ifparameters) { foreach($structure->parts[$i]->parameters as $object) { if(strtolower($object->attribute) == 'name') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['name'] = $object->value; } } } if($attachments[$i]['is_attachment']) { $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1); if($structure->parts[$i]->encoding == 3) { // 3 = BASE64 $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); } elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); } $savepath = $savedir . $attachments[$i]['filename']; file_put_contents($savepath, $attachments[$i]['attachment']); } } } $name = $structure->parts[1]->dparameters[0]->value; $overview = imap_fetch_overview($inbox,$email_number,0); $msg = imap_fetchbody($inbox,$email_number,1.2); $message=''; if($msg=='') { $message = imap_fetchbody($inbox,$email_number,2.0); }else{ $message=$msg; } $sub=$overview[0]->subject; $from=$overview[0]->from; $arr = explode('<', $from); $from_mail = $arr[1]; if($from_mail!='') { $from=str_replace('>','',$from_mail); } $randstr=''; srand((double)microtime()*1000000); $chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; while(strlen($randstr)<5) { $randstr.=substr($chars,(rand()%(strlen($chars))),1); } 

Любой, пожалуйста, помогите мне … Спасибо заранее

Ваша проблема в этой строке:

 $msg = imap_fetchbody($inbox,$email_number,1.2); 

1.2 является частью электронной почты TEXT / HTML, которая используется для тела электронной почты html.

1.1 – TEXT / PLAIN – текстовое тело электронной почты – для текстовых сообщений вам нужно будет использовать этот текст.