Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// read_gmail.php
// Connect to gmail
$url = '{}INBOX';
$user = '';
$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/>';
// mark as seen
imap_setflag_full($inbox, $mail, '\\Seen \\Flagged');
// Disconnect from gmail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment