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
我将如何去做呢?谢谢。
I am using Zend Mail in order to get a list of email messages from my POP3 server, and display it on a web page. Here is my code:
<?
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>";
}
?>
The problem is that some of the emails are showing up like this:
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--
which makes it hard to read the actual body content of the message. I want it to show up like this:
From: 'Stan Flusterflap '
Subject: hi
Content: hi
How would I go about doing this? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getContent
方法获取整个消息正文。您看到的是整个正文,由两个 MIME 部分及其分隔符组成。手册中有一个示例 -- 搜索“multipart part” " -- 如何直接使用 MIME 部分。
The
getContent
method gets the entire message body. What you're seeing there is the entire body, composed of two MIME parts and their separators.There's an example in the manual -- search for "multipart part" -- of how to work with the MIME parts directly.