我是PHP的PEAR扩展的新手,并且想知道如何使用PEAR列出邮箱中的所有邮件。我已成功制作了一个程序,可以找到您最近的消息,但我想这样做,以便它可以列出您邮箱中的所有消息。我相信这将使用PEAR的pop3部分完成,但我不确定如何去做。有人有什么想法吗?这可能与PEAR有关吗? 我目前有此代码列出最新消息:
//create pear object
require_once 'Net/POP3.php';
$pop3 =& new Net_POP3();
//connect to email provider
if(PEAR::isError($ret = $pop3->connect($host, $port))){
throw new ConnException($ret->getMessage());
}
if(PEAR::isError($ret = $pop3->login($user, $pass, 'USER'))){
throw new ConnException($ret->getMessage());
}
//get num messages and mailbox size
echo $pop3->numMsg() . ' messages in mailbox, ' . $pop3->getSize() . ' bytes <br/>';
//get the headers for the most recent message
if($pop3->numMsg() > 0){
$msgData = $pop3->getParsedHeaders($pop3->numMsg());
echo 'The most recent email in your inbox is from ' .htmlentities($msgData['From']) . ' with the subject \'' . htmlentities($msgData['Subject']) . '\'';
}
//disconnect from the provider
$pop3->disconnect();
有人可以给我一些提示或代码,会修改它以列出邮箱中的所有邮件吗? 谢谢!
答案 0 :(得分:1)
简单地显示所有电子邮件只是循环遍历它们。
<?php
//get num messages and mailbox size
$messageCount = $pop3->numMsg();
echo $messageCount . ' messages in mailbox, ' . $pop3->getSize() . ' bytes <br/>';
//get the headers for all messages
// NOTE: need to be careful not to overflow the memory (Only grab the latest 500, etc)
for ($i = $messageCount; $i > 0; $i--) {
$msgData = $pop3->getParsedHeaders($i);
echo "Message: $i \n";
echo " From: " . htmlentities($msgData['From']) . "\n";
echo "Subject: " . htmlentities($msgData['Subject']) . "\n";
echo "-------------------------------------------------\n";
}