The read only part will not let the imap mark the email as read, meaning it will not move the email only copy not to another folder
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?php $inbox = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', 'emailaddress', 'password', OP_READONLY); // $emails = imap_search($inbox,'FROM "emailaddress"'); $emails = imap_search($inbox, 'SINCE "24-Feb-2013" BODY "mike"'); // $emails = imap_search($inbox, 'SINCE "20-May-2013" BEFORE "26-Jun-2013"'); $result = count($emails); echo "You have <b>$result</b> in your mailbox<p>"; if($emails){ $limit = 1000; //loop each email retrieve. foreach($emails as $email_number){ //fetch the email over view... if you want to see the overview of the email.(OPTIONAL) $overview = imap_fetch_overview($inbox,$email_number,0); //fetch the email content body... This will show only the email content. $message = imap_fetchbody($inbox, $email_number,"1"); //set the message format to UTF-8 $message = imap_utf8($message); $message = strip_tags($message); //add break in each line of the image. $message = nl2br($message); //Now, you can either echo the image or USE for for other functions like saving in database. echo "<hr>".$message; // increment limit $limit++; //if limit is true. Break the loop and exit. if($limit === 1) break; } } imap_close($inbox); ?> |