2011-12-11 95 views
0

人可以帮我用代码来获取未读的Gmail邮件的数量到PHP的数量?如何获得未读的Gmail邮件

+0

我还没有特里,因为我不知道如何开始 – Samjack

+1

可能重复:http://stackoverflow.com/questions/7003150/how-to-get-gmail-unread-count –

+0

欢迎来到SO!在问之前请始终Google。谷歌搜索'如何获得未读的Gmail邮件数量php'变成了好的结果。谢谢! –

回答

0

连接到使用从IMAP模块功能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"