The EIMap Class allows to have easy access to imap extension functions to read and parse messages from a mailbox.
Extract and place the contents of the package into your extensions folder (you can place it where ever you wish, the extensions folder is for the sake of the example).
reading unseen emails
Yii::import('ext.EImap.EIMap', true); // please replace the server path to the one of your // inbox + your username and password $imap = new EIMap('{imap.server.com:993}/imap/ssl}INBOX', 'yourusername', 'yourpassword'); if($imap->connect()) { // we are set lets search for unseen $unseen = $imap->searchmails( EIMap::SEARCH_UNSEEN ); if($unseen && is_array($unseen)) // do we have any? { // put new ones first rsort($unseen); foreach($unseen as $msgId) { $mail = $imap->getMail( $msgId ); echo '<pre>'.( CVarDumper::dumpAsString( $mail ) ).'</pre>'; } } $imap->close(); // close connection }
reading mails overviews
Yii::import('ext.EImap.EIMap', true); // please replace the server path to the one of your // inbox + your username and password $imap = new EIMap('{imap.server.com:993}/imap/ssl}INBOX', 'yourusername', 'yourpassword'); if($imap->connect()) { // get mailbox info $mailboxCheck = $imap->getCheck(); // read all messages overviews $result = $imap->getMailboxOverview("1:{$mailboxCheck->Nmsgs}"); // if we have any display them foreach($result as $overview) { echo "#{$overview->msgno} ({$overview->date}) - From: {$overview->from} {$overview->subject}\n"; echo "size: {$overview->size}"; echo '<pre>'.CVarDumper::dumpAsString($overview).'</pre>'; // sender again please? echo '<pre>'.CVarDumper::dumpAsString($imap->getSender($overview->msgno)).'</pre>'; } $imap->close(); // close connection }
====
well-built beautifully designed web applications
www.clevertech.biz
Total 7 comments
replace
by
if not, the code only worked when the attachments were images, a non sense, ifdisposition has nothing to do
.... modifying this extension to be usable, ....I'll upload the result
imap_open not work with 6 parameters if php<5.3.2, replace imap_open line, by this:
Good to hear. If there are any problems, please ask a question at Stackoverflow.
Thans,it's working now.
HI Ivo Renkema
i changed my code with that you mentioned but not supporting any video formated file type
I try this extension but it 's not working for me .
I use this $imap = new EIMap('{imap.gmail.com:993/imap/ssl}INBOX', 'myemail@gmail.com', 'mypasswor')
but it's return blank page. I don't know why
I need help.
Thanks for the extension!
It took me while to get it to work for video-file attachments.
First, I expanded $imgTypes to include 'mp4', et cetera. But even then the download of the attachment failed.
Secondly, I believe there is a bug in getAttachment(). The line:
should actually be:
Is that right? After the above changes, downloading video attachments seems to work.
Leave a comment
Please login to leave your comment.