Skip to content

Instantly share code, notes, and snippets.

@aansubarkah
Last active December 11, 2016 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aansubarkah/faaefe8a9197827c569b815f280e84ee to your computer and use it in GitHub Desktop.
Save aansubarkah/faaefe8a9197827c569b815f280e84ee to your computer and use it in GitHub Desktop.
<?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 . '.&nbsp;';
echo $header->fromaddress . '&nbsp;';
echo $header->subject . '&nbsp;';
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