Retrieve Your Gmail Emails Using PHP and IMAP

<?php
$hostname = ‘{imap.googlemail.com:993/imap/ssl/novalidate-cert}INBOX’;
$username=”xxx@gmail.com”;
$password=”xxxx”;
$inbox=imap_open($hostname,$username,$password);
$email=imap_num_msg($inbox);
$newsArray=array();
$o=0;
for($i=$email;$i>$email-50;$i–){

$news=array();
$news[‘text’]=imap_fetchbody($inbox,$i,1);
$overview=imap_fetch_overview($inbox,$i,0);
$news[‘author’]=$overview[0]->from;
$news[‘status’]=$overview[0]->seen;
$news[‘date’]=$overview[0]->date;
$news[‘title’]=$overview[0]->subject;
array_push($newsArray,$news);
}
foreach($newsArray as $n){
echo “Author”.$n[‘author’].”<br>”;
echo “Title”.$n[‘title’].”<br>”;
echo “Date”.$n[‘date’].”<br>”;
echo “Text”.$n[‘text’].”<br>”;
echo “<h1>”.$o++.”</h1>”;
}
?>

Advertisements

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