PHP 显示未读邮件数 [英] PHP Displaying unread mail count
问题描述
我正在使用 php imap 类.我的盒子里有很多邮件,但是使用这个脚本我只能检索未读邮件.我该怎么做?
I am using php imap class. In my box I have a lot of mail, but with this script I would retrieve only the unreaded mail. How can I do it?
if ($mbox=imap_open( "{" . $mailserver . ":" . $port . "}INBOX", $user, $pass ))
{
echo "Connected
";
} else { exit ("Can't connect: " . imap_last_error() ."
"); echo "FAIL!
"; };
if ($hdr = imap_check($mbox)) {
$msgCount = $hdr->Nmsgs;
echo "Ci sono ".$msgCount." mail";
} else {
echo "Failed to get mail";
}
如果我这样做
$overview=imap_fetch_overview($mbox,"1:$msgCount",0);
脚本加载到无限时间.
imap_search UNSEEN 解决方案不好,因为 pop3 没有使用这个标志.那我该怎么办??????非常感谢.
The imap_search UNSEEN solution is not good because pop3 don't use this flag. So how can I do?????? Thanks a lot.
推荐答案
您可以遵循以下两种方式:
There is two way you can follow:
1.循环浏览消息
$count = imap_num_msg($connection);
for($msgno = 1; $msgno <= $count; $msgno++) {
$headers = imap_headerinfo($connection, $msgno);
if($headers->Unseen == 'U') {
... do something ...
}
}
2.使用 imap_search
有一个名为 UNSEEN 的标志,您可以使用它来搜索未读电子邮件.您可以像这样使用 UNSEEN 标志调用 imap_search 函数:
There's a flag called UNSEEN which you can use to search for the unread emails. You would call the imap_search function with the UNSEEN flag like so:
$result = imap_search($connection, 'UNSEEN');
如果您需要将此与更多搜索标志结合使用,例如搜索来自 me@example.com 的消息,您可以这样做:
If you need to combine this with more search flags, for example searching for messages from me@example.com, you could do this:
$result = imap_search($connection, 'UNSEEN FROM "me@example.com"');
有关可用标志的完整列表,请参阅 PHP 网站 (www.php.net/imap_search) 上 imap_search 手册页的标准部分
For a complete list of the available flags, refer to the criteria section of the imap_search manual page on the PHP website (www.php.net/imap_search)
来源:http://www.electrictoolbox.com/php-imap-unread-消息/
这篇关于PHP 显示未读邮件数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!