我正在集成网络邮件收件箱访问流程。请参阅下面的我的代码。它不会收到未读消息,它会带来所有消息。我怎样才能只收到未读消息请建议我。
$emails = imap_search($openmail, 'UNSEEN');
请参阅上面的行,它不起作用。
$authhost="{example.com:110/pop3}INBOX";
$username="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f3737370f2a372e223f232a612c2022" rel="noreferrer noopener nofollow">[email protected]</a>";
$password="wxwxwxw";
ini_set('max_execution_time', 0);
/* try to connect */
$inbox = imap_open($authhost,$username,$password) or die('Cannot connect to Mail Server: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox, 'UNSEEN');
// echo count($emails);exit;
/* if emails are returned, cycle through each... */
if($emails) {
/* begin output var */
$output = '';
/* put the newest emails on top */
// rsort($emails);
/* for every email... */
// $count = 1;
foreach($emails as $email_number) {
$head = imap_header($inbox, $email_number);
/* get information specific to this email */
$overview = imap_fetch_overview($inbox,$email_number,0);
/* echo "<pre>";
print_r($overview);exit; */
$obj_thang = imap_headerinfo($inbox, $email_number);
// print_r($overview);exit;
$message = imap_body($inbox,$email_number,2);
/* output the email header information */
$output.= $obj_thang->subject;
//$output.= $obj_thang->fromaddress."<br/>";
$output.= $obj_thang->reply_toaddress."<br/>";
}
echo $output;
}
最佳答案
您正在连接到 POP3,而不是 IMAP。 Pop3 不支持服务器端搜索,也不支持未见消息与已见消息的概念。
关于php - 如何在php中从服务器webmail获取未读消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30637807/