Why doesn't this mail message decode correctly?

后端 未结 2 433

I have this code. It\'s from the Zend Reading Mail example.

$message = $mail->getMessage(1);

// output first text/plain part
$foundPart = null;
foreach (         


        
2条回答
  •  感情败类
    2021-01-06 10:38

    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
    }
    

提交回复
热议问题