Last active
December 11, 2016 09:26
-
-
Save aansubarkah/faaefe8a9197827c569b815f280e84ee to your computer and use it in GitHub Desktop.
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 | |
// read_gmail.php | |
set_time_limit(4000); | |
// Connect to gmail | |
$url = '{imap.gmail.com:993/imap/ssl}INBOX'; | |
$user = 'username_gmail_anda@gmail.com'; | |
$pass = 'isi_dengan_password_anda'; | |
// try to connect | |
$inbox = imap_open($url, $user, $pass) or die('Error When Connect: ' . imap_last_error()); | |
// get unseen (unread) emails | |
$mails = imap_search($inbox,'UNSEEN'); | |
$i = 1; | |
foreach($mails as $mail) { | |
// email header | |
$header = imap_headerinfo($inbox, $mail); | |
// email body | |
$body = imap_body($inbox, $mail); | |
echo $i . '. '; | |
echo $header->fromaddress . ' '; | |
echo $header->subject . ' '; | |
echo $body; | |
echo '<br/>'; | |
$i++; | |
// mark as seen | |
imap_setflag_full($inbox, $mail, '\\Seen \\Flagged'); | |
} | |
// Disconnect from gmail | |
imap_expunge($inbox); | |
imap_close($inbox); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment