PHP 使用PEAR通过POP3检索电子邮件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 使用PEAR通过POP3检索电子邮件相关的知识,希望对你有一定的参考价值。

<?php
// include class
include("Net/POP3.php");

// initialize object
$pop3 = new Net_POP3();

// attempt connection to server
if (!$pop3->connect("example.com", 110)) {
    die("Error in connection");
}

// attempt login
$ret = $pop3->login("john", "doe");
if (is_a($ret, 'PEAR_Error')) {
    die("Error in authentication: " . $ret->getMessage());
}

// print number of messages found
echo $pop3->numMsg() . " message(s) in mailbox\n";

// print message headers
if ($pop3->numMsg() > 0) {
    for ($x=1; $x<=$pop3->numMsg(); $x++) {
        $hdrs = $pop3->getParsedHeaders($x);
        echo $hdrs['From'] . "\n" . $hdrs['Subject'] . "\n\n";  
    }
}

// disconnect from server
$pop3->disconnect();
?>

以上是关于PHP 使用PEAR通过POP3检索电子邮件的主要内容,如果未能解决你的问题,请参考以下文章