PHP显示未读邮件数 [英] PHP Displaying unread mail count
问题描述
在我的框中我有很多邮件,但是使用这个脚本,我将只检索未读的邮件。
我该怎么做?
if($ mbox = imap_open({。$ mailserver $ port。} INBOX,$ user,$ pass))
{
echoConnected\\\
;
} else {exit(Can not connect:。imap_last_error()。\\\
);回声FAIL!\\\
; };
if($ hdr = imap_check($ mbox)){
$ msgCount = $ hdr-> Nmsgs;
echoCi sono$ msgCount。mail;
} else {
echo无法获取邮件;
}
如果我做
$概述= imap_fetch_overview($ MBOX, 1:$ MSGCOUNT,0);
脚本加载到无限时间。
imap_search UNSEEN解决方案不好,因为pop3不使用此标志。
那么我该怎么办?
非常感谢。
有两种方法可以遵循:
1。循环邮件
$ count = imap_num_msg($ connection); ($ msgno = 1; $ msgno< = $ count; $ msgno ++)
{
$ headers = imap_headerinfo($ connection,$ msgno);
if($ headers-> Unseen =='U'){
... do something ...
}
}
2。使用imap_search
有一个名为UNSEEN的标志,可以用来搜索未读的电子邮件。您可以使用UNSEEN标志调用imap_search函数,如下所示:
$ result = imap_search($ connection,'UNSEEN');
如果您需要将其与更多的搜索标记相结合,例如从我的示例搜索消息。 com,你可以这样做:
$ result = imap_search($ connection,'UNSEEN FROMme@example.com );
有关可用标志的完整列表,请参阅imap_search手册页的条款部分PHP网站(www.php.net/imap_search)
资料来源: http://www.electrictoolbox.com/php-imap-unread-messages/
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\n";
} else { exit ("Can't connect: " . imap_last_error() ."\n"); echo "FAIL!\n"; };
if ($hdr = imap_check($mbox)) {
$msgCount = $hdr->Nmsgs;
echo "Ci sono ".$msgCount." mail";
} else {
echo "Failed to get mail";
}
If I do
$overview=imap_fetch_overview($mbox,"1:$msgCount",0);
the script load to an infinity time.
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. Looping through the messages
$count = imap_num_msg($connection);
for($msgno = 1; $msgno <= $count; $msgno++) {
$headers = imap_headerinfo($connection, $msgno);
if($headers->Unseen == 'U') {
... do something ...
}
}
2. Using 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');
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"');
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)
Source: http://www.electrictoolbox.com/php-imap-unread-messages/
这篇关于PHP显示未读邮件数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!