如何获取未读Gmail邮件的数量 [英] How to get the number of unread gmail mails
本文介绍了如何获取未读Gmail邮件的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过代码可以帮助我获得未读gmail电子邮件的数目到php吗?使用来自IMAP模块的函数的IMAP协议 http://php.net/manual/zh/book .imap.php
$ mbox = imap_open({imap.example.org:143}INBOX, username,password)
或die(无法连接:。imap_last_error());
$ MC = imap_check($ mbox);
//获取INBOX中所有消息的概览
$ result = imap_fetch_overview($ mbox,1:{$ MC-> Nmsgs},0);
$ seen = 0;
$ unseen = 0;
foreach($ result as $ overview){
if($ overview-> seen){
$ counter ++;
} else {
$ unseen ++;
}
}
imap_close($ mbox);
echo看到$看到,看不见$看不到
Can someone help me with a code to get the numbers of unread gmail emails to php?
解决方案
Connect to gmail via IMAP protocol using functions from the IMAP module http://php.net/manual/en/book.imap.php
$mbox = imap_open("{imap.example.org:143}INBOX", "username", "password")
or die("can't connect: " . imap_last_error());
$MC = imap_check($mbox);
// Fetch an overview for all messages in INBOX
$result = imap_fetch_overview($mbox,"1:{$MC->Nmsgs}",0);
$seen = 0;
$unseen = 0;
foreach ($result as $overview) {
if($overview->seen){
$counter++;
} else {
$unseen++;
}
}
imap_close($mbox);
echo "Seen $seen, unseen $unseen"
这篇关于如何获取未读Gmail邮件的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文