Skip to content

Instantly share code, notes, and snippets.

@tutweb
Created May 14, 2014 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tutweb/bcaa4098368b4e4d7400 to your computer and use it in GitHub Desktop.
Save tutweb/bcaa4098368b4e4d7400 to your computer and use it in GitHub Desktop.
Mendapatkan list email dari Gmail dengan PHP
<?php
function check_email($username, $password)
{
//Connect Gmail feed atom
$url = "https://mail.google.com/mail/feed/atom";
// Send Request to read email
$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;
}
$feed = check_email("YOUR_USERNAME", "YOUR_PASSWORD");
$x = new SimpleXmlElement($feed);
echo "<ul>";
foreach($x->entry as $entry)
{
echo '<li><p><strong>'. $entry->title.'</strong><br>';
echo $entry->summary;
echo '</p></li>';
}
echo "</ul>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment