Skip to content

Instantly share code, notes, and snippets.

@jploh
Created January 21, 2015 07: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 jploh/f7e01fae9f5b23134780 to your computer and use it in GitHub Desktop.
Save jploh/f7e01fae9f5b23134780 to your computer and use it in GitHub Desktop.
Fetch IMAP Email using PHP
<?php
$mbox = imap_open("{imap.gmail.com:993/imap/ssl}---LABEL---", "---EMAIL ADDRESS---", "---PASSWORD---")
or die("can't connect: " . imap_last_error());
$messages = imap_search($mbox, 'ALL');
if($messages) {
rsort($messages);
foreach($messages as $uid) {
$headers = imap_fetchheader($mbox, $uid);
$headers = imap_rfc822_parse_headers($headers);
$payload = utf8_encode(quoted_printable_decode(imap_fetchbody($mbox, $uid, 2)));
imap_mail_move($mbox, $uid, '---NEW LABEL---');
$c++;
//if($c >= 10)
//break;
}
}
//imap_mail_move($mbox, implode(',', $uids), '---NEW LABEL---');
imap_close($mbox);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment