Australia's Leading Digital Marketing Experts. T. 1300 235 433  |  Aggregation Enquires Welcome

Gmail RSS Feed with PHP

This cool PHP function will create an RSS feed from the email in your Gmail inbox. It's a good way of including your mail with all the other content you aggregate in your RSS reader. I haven't tried it in a while so no longer sure if it still works.

1
<?php 
2
/*
3
 Gmail RSS Feed with PHP
4
 http://www.beliefmedia.com/code/php-snippets/gmail-rss-feed
5
*/
6
 
7
function beliefmedia_gmail_rss_feed($username, $password) {
8
 $url = "https://mail.google.com/mail/feed/atom";
9
 
10
  $curl = curl_init();
11
  curl_setopt($curl, CURLOPT_URL, $url);
12
  curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
13
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
14
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
15
  curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
16
  curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
17
  curl_setopt($curl, CURLOPT_ENCODING, "");
18
  $gmail_data = curl_exec($curl);
19
  curl_close($curl);
20
 
21
 return $gmail_data;
22
}
23
 
24
header('Content-Type:text/xml; charset=UTF-8');
25
echo beliefmedia_gmail_rss_feed('YourUsername@gmail.com', 'Password');

Take appropriate measures to ensure security.

Like this article?

Share on facebook
Share on Facebook
Share on twitter
Share on Twitter
Share on linkedin
Share on Linkdin
Share on pinterest
Share on Pinterest

Leave a comment