我需要在 php 中提取邮件的正文。
目前我正在使用 mimemailparser "getmessagebody" 函数来检索邮件正文。
它在没有任何其他 (.msg) 文件的邮件有附件时运行良好,但如果邮件包含的附件也是 .msg 格式的邮件,它会获取附件的正文而不是正文当前邮件。使用以下函数和代码。
public function getMessageBody($type = 'text') {
$body = false;
$mime_types = array(
'text'=> 'text/plain',
'html'=> 'text/html'
);
if (in_array($type, array_keys($mime_types))) {
foreach($this->parts as $part) {
if ($this->getPartContentType($part) == $mime_types[$type]) {
$headers = $this->getPartHeaders($part);
$body = $this->decode($this->getPartBody($part), array_key_exists('content-transfer-encoding', $headers) ? $headers['content-transfer-encoding'] : '');
}
}
} else {
throw new Exception('Invalid type specified for MimeMailParser::getMessageBody. "type" can either be text or html.');
}
return $body;
}
代码:
$this->parsed->setText($this->mail);
$this->message = $this->parsed->getMessageBody('text');
问题:getmessagebody 检索附加邮件的正文,而不是原始邮件。请问有什么解决办法吗?