如何获取电子邮件正文..
使用此示例,只提取了约25%的所有电子邮件正文!?
$structure = imap_fetchstructure($this->stream, $header->msgno);
if(!empty($structure->parts[1])){
$message = imap_fetchbody($this->stream, $header->msgno, '1');
switch($structure->parts[1]->encoding){
case 1:
$message = imap_8bit($message);
break;
case 3:
$message = imap_base64($message);
break;
case 4:
$message = imap_qprint($message);
break;
}
echo $message;
}
// gets 35 of 131
$message = imap_fetchbody($this->stream, $header->msgno, '1');
// gets 10 of 131
$message = imap_fetchbody($this->stream, $header->msgno, '1.2');
答案 0 :(得分:0)
找到解决方案:D
public function parse_mail($header){
$structure = imap_fetchstructure($this->stream, $header->msgno);
if(isset($structure->parts)){
$parse = $this->parse_parts($structure->parts, $header->msgno);
}
else{
$parse = $this->parse_parts($structure, $header->msgno);
}
if($parse){
print_r($parse);
}
}
private function parse_parts($parts, $msgno){
$message = imap_fetchbody($this->stream, $msgno, '1');
if(!empty($parts->encoding)){
switch($parts->encoding){
/*case 1:
$message = imap_8bit($message);
break;*/
case 3:
$message = imap_base64($message);
break;
case 4:
$message = imap_qprint($message);
break;
}
}
return $message;
}