【问题标题】:List all messages in a mailbox using PEAR使用 PEAR 列出邮箱中的所有消息
【发布时间】:2013-05-21 01:52:59
【问题描述】:

我对 PHP 的 PEAR 扩展非常陌生,想知道如何使用 PEAR 列出邮箱中的所有消息。我已经成功地制作了一个可以找到您最近的消息的程序,但我想制作它以便它可以列出您邮箱中的所有消息。我相信这可以使用 PEAR 的 pop3 部分来完成,但我不确定如何去做。有人有什么想法吗?这可能与梨有关吗? 我目前有这个代码来列出最近的消息:

            //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();

有人可以给我一些提示或代码,将其修改为列出邮箱中的所有消息吗? 谢谢!

【问题讨论】:

标签: php email pear


【解决方案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";
}

【讨论】:

  • 好吧,酷。是否可以打印出带有主题的消息?
猜你喜欢
  • 2012-07-22
  • 1970-01-01
  • 2016-01-27
  • 2016-08-10
  • 1970-01-01
  • 2014-08-26
  • 2018-04-28
  • 2014-03-21
  • 1970-01-01
相关资源
最近更新 更多