Fatal error: Uncaught exception 'Zend\Mail\Exception\RuntimeException' with message 'Malformed header detected' in /var/www/html/plugins/ZendFramework/ZendFramework-2.4.7/library/Zend/Mail/Headers.php on line 88ZendMail - 标题错误
这是我尝试使用Zend\Mail\Storage\Imap::getMessage()
函数时得到的错误消息。如果我注释掉这一行,错误被引发(更准确地说,我必须注释掉这两行,这个错误是从同一个函数抛出的),我可以读取这个消息的主题,但后来一些电子邮件,我得到一个:
Fatal error: Uncaught exception 'Zend\Mail\Header\Exception\InvalidArgumentException' with message 'Invalid header value detected' in /var/www/html/plugins/ZendFramework/ZendFramework-2.4.7/library/Zend/Mail/Header/GenericHeader.php on line 61
正如我在测试该插件,我没有使用任何其他分机或插件,而我得到了这些错误,只有Xdebug的PHP扩展,用于调试。这里是我的全部代码:
try {
$mail = new Zend\Mail\Storage\Imap(array('host' => 'my.mail.host',
'user' => '[email protected]',
'password' => 'xxxxxxxxx'));
}
catch (Zend\Mail\Exception $e) {
print_r($e);
}
$undecodable=array();
$mail->selectFolder('INBOX');
$list=array(1,2,3,4);
foreach ($list as $mid) {
$message=$mail->getMessage($mid);
$content=array(
'html' => array(
'part' => null,
'content' => null
),
'plain' => array(
'part' => null,
'content' => null
)
);
foreach (new RecursiveIteratorIterator($message) as $part) {
try {
$strtok=strtok($part->contentType, ';');
if (($strtok == 'text/html') || ($strtok == 'text/plain')) {
switch ($part->contentTransferEncoding) {
case 'base64':
$contentDecoded = base64_decode($part->getContent());
break;
case 'quoted-printable':
$contentDecoded = quoted_printable_decode($part->getContent());
break;
case 'default':
$contentDecoded='undecodable';
$undecodable[]=$part->contentTransferEncoding;
break;
}
$strtok=explode("/",$strtok);
$strtok=$strtok[1];
$content[$strtok]['part']=$part;
$content[$strtok]['content']=$contentDecoded;
}
} catch (Zend\Mail\Exception $e) {
// ignore
}
}
echo "Message: " . $message->subject."<BR>";
if (!empty($content['html']['content'])) echo "HTML part found! ";
if (!empty($content['plain']['content'])) echo "Plain part found! ";
echo "<BR><BR>Next message";
}
exit;
注:消息ID是正确的,我可以通过远程登录邮件服务器获取所有的,他们都存在