Design Grid

Icon

Resources and Tutorials for Web Designers and Developers

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]

Category: Resources, Tutorials

Tagged: ,

2 Responses

  1. Joran says:

    Thanks for this :) guess this is “part 1 of creating a board page”, lol :)

Leave a Reply