How to get unread Emails count in Gmail Account using PHP.You can get unread Emails count by gmail feeds.Here is a example how to get unread email count in your gmail account. In here you must enter your gmail user name and password to access account.Another article, I was describes PHP Import Email Addresses from Gmail Accounts.But there user must be grant access his account to access data.I’ll describes how to access by using user grant access to get email count in later article.
You must only run this file to get unread email count.
//fucntion to get unread emails taking username and password as parametes
function check_email($username, $password)
//url to connect to
$url = "https://mail.google.com/mail/feed/atom";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_ENCODING, "");
$curlData = curl_exec($curl);
//returning retrieved feeds
How to call use above function.
$feeds = check_email("email@example.com", "yourpassword");
$xmlobjc = new SimpleXMLElement($feeds);
If you want to get xml format, you must set the Content-Type as xml.
//making page to behave like xml document to show feeds