Zend Mail消息内容

时间:2011-04-04 05:07:29

标签: php zend-framework ubuntu pop3 zend-mail

我正在使用Zend Mail从我的POP3服务器获取电子邮件列表,并将其显示在网页上。这是我的代码:

<?

require("Zend/Mail/Storage/Pop3.php");

$mail = new Zend_Mail_Storage_Pop3(array('host'     => 'localhost',
                                         'user'     => 'person',
                                         'password' => 'awesome'));

// show the mail!

echo "You have " . $mail->countMessages() . " messages! <br><br>";

foreach ($mail as $message) {
  echo "From: '{$message->from}'<br> Subject: {$message->subject}<br>";
  echo "Content: " . $message->getContent() . "<br><br>";
}

?>

问题是有些电子邮件显示如下:

    From: 'Trey '
Subject: WOMBATS WOMBATS
Content: --Apple-Mail-1--609821059 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii SWIMMING IN THE OCEAN CAUSIN' A COMOTION CUZ THEY SUCK --Apple-Mail-1--609821059 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii SWIMMING IN THE OCEAN 
CAUSIN' A COMOTION 
CUZ THEY 
SUCK
--Apple-Mail-1--609821059-- 

这使得难以阅读邮件的实际正文内容。我想让它像这样出现:

From: 'Stan Flusterflap '
Subject: hi
Content: hi 

我该怎么做呢?谢谢。

1 个答案:

答案 0 :(得分:3)

getContent方法获取整个邮件正文。您所看到的是整个主体,由两个MIME部分及其分隔符组成。

There's an example in the manual - 搜索“多部分” - 如何直接使用the MIME parts