Created
May 14, 2014 14:25
-
-
Save tutweb/bcaa4098368b4e4d7400 to your computer and use it in GitHub Desktop.
Mendapatkan list email dari Gmail dengan PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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