Why doesn't this mail message decode correctly?

試著忘記壹切 提交于 2019-12-01 00:11:52

This could be because of base64 encoding. The Zend_Mail docs say (under 'encoding'):

...All other attachments are encoded via base64 if no other encoding is given in the addAttachment() call or assigned to the MIME part object later.

Try something like:

echo base64_decode($foundPart->getContent());

Also, read: http://framework.zend.com/manual/en/zend.mail.encoding.html

Hope that helped somehow.

I ran into some similar issues while learning how to use Zend_Mail for reading emails. You will need to add additional logic that Zend_Mail doesn't implement, such as decoding encoded emails, and converting the character set. Here's what I'm doing after finding the plain text part:

$content = $foundPart->getContent();

switch ($foundPart->contentTransferEncoding) {
    case 'base64':
        $content = base64_decode($content);
        break;
    case 'quoted-printable':
        $content = quoted_printable_decode($content);
        break;
}

//find the charset
preg_match('/charset="(.+)"$/', $foundPart->contentType, $matches);
$charset = $matches[1];

if ($charset == 'iso-8859-1') {
    $content = utf8_encode($content); //convert to utf8
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!