Mar 11, 2010
Display your unread gmail count using PHP
This little snippet of code does amazing things!
Using imap_open, you can display your unread email count from your googlemail (or any pop/imap server). I used it for my status board, and it works a treat.
$mbox = imap_open ("{imap.googlemail.com:993/imap/ssl/novalidate-cert}INBOX",
"gmailusername", "gmailpassword", OP_READONLY)
or die("can't connect: " . imap_last_error());
$check = imap_mailboxmsginfo($mbox);
if ($check) {
print $check->Unread; //. "/" . $check->Nmsgs;
} else {
print "Failed";
}
Just a couple of things to note:
- novalidate-cert – This is important for Google Mail, otherwise you will get authentication failures
- Make sure you have php5-imap installed. [sudo apt-get install php5-imap ; /etc/init.d/apache2 restart]
Thanks for this :) guess this is “part 1 of creating a board page”, lol :)
I guess this counts as a pt1 :)