Check Gmail email using PHP Script

Please save this content as  index.php

 

 

***************************

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”><html xmlns=”http://www.w3.org/1999/xhtml”><head><meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /><title>Haneef Script to Check Gmail email using PHP Script</title>

<style type=”text/css”>body,td,th { font-family: Georgia,”Times New Roman”,Times,serif;; font-size: 12px; color: #333;}body { margin-left: 0px; margin-top: 30px; margin-right: 0px; margin-bottom: 0px;}.maindiv{ width:690px; margin:0 auto; padding:20px; background:#CCC;}.innerbg{ padding:6px; background:#FFF;}.links{ font-weight:bold; color:#c24f00; text-decoration:none; font-size:12px;}a{ text-decoration:none; outline:none;}.newsli li{ padding:4px 0px;}.info{ font-size:10px; color:#666;}</style></head>

<body><div>
<div class=”maindiv”>
<div class=”innerbg”>
<table width=”100%” border=”0″ cellpadding=”2″ cellspacing=”2″>

<tr>
<td align=”center” valign=”middle”>
<form method=”post”>
<table width=”100%” border=”0″ cellspacing=”2″ cellpadding=”2″>

<tr>
<td width=”15%”>Username</td>
<td width=”27%”><label for=”username”></label>
<input name=”username” type=”text” id=”username” /></td>
<td width=”10%”>Password</td>
<td width=”25%”><label for=”password”></label>
<input name=”password” type=”password” id=”password” /></td>
<td width=”23%”><input type=”submit” name=”getgmails” id=”getgmails” value=”Get Gmail” /></td>
</tr>
<tr>
<td colspan=”5″>
<div class=”newsli”>
<?php
if(isset($_POST[‘getgmails’]))
{
//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”;

// sendRequest
$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);
curl_close($curl);

//returning retrieved feed
return $curlData;
}

//making page to behave like xml document to show feeds
//header(‘Content-Type:text/html; charset=UTF-8’);
//calling function
$feed = check_email($_POST[‘username’], $_POST[‘password’]);
$x = new SimpleXmlElement($feed);
echo “<ul>”;
foreach($x->entry as $entry)
{
?>
<li><p><strong class=”links”><?php echo $entry->title; ?></strong><br>
<?php echo $entry->summary; ?>
</p></li>
<?php
}
echo “</ul>”;
}
?>
</div>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</div>
</div>
</body></html>

 

*******************************.