Created
January 21, 2015 07:26
-
-
Save jploh/f7e01fae9f5b23134780 to your computer and use it in GitHub Desktop.
Fetch IMAP Email using 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 | |
$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