Gmail rss feed with unread email in PHP

Posted: January 22, 2011 in PHP5
Tags:

<?php
$username = “gmail username”;
$password = “gmail password”;

// Initialise cURL
$c = curl_init(‘https://gmail.google.com/gmail/feed/atom&#8217;);

$headers = array(
“Host: gmail.google.com”,
“Authorization: Basic “.base64_encode($username.':’.$password),
“User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4″,
“Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5″,
“Accept-Language: en-gb,en;q=0.5″,
“Accept-Encoding: text”,
“Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7″,
“Date: “.date(DATE_RFC822)
);

curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($c, CURLOPT_COOKIESESSION, true);
curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($c, CURLOPT_UNRESTRICTED_AUTH, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 1);

$str = curl_exec($c);
echo $str;

curl_close($c);
?>

About these ads
Comments
  1. Great post. I was checking continuously this blog and I’m quite impressed! Extremely helpful information particularly the first part. I care for such info a lot. I was seeking this particular info for a very long time. Thank you and good luck.

  2. Excellent post. I was checking constantly this blog and I’m quite impressed! Extremely useful info particularly the last part. I care for such information a lot. I was seeking this certain information for a long time. Thank you and good luck.

  3. thank for u shared :)

  4. Petter says:

    doesnt work! ;(

  5. pulis says:

    thanks, but how can i read all emails, read and unread?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s