PHP: Download incoming email from POP3 or IMAP, parse it, and mark it as read/delete on server
Asked Answered
B

2

9

I'm trying to add incoming email to my web application. It's built on CodeIgniter and PHP, and as far as I can tell I haven't found any CI libraries to do this.

What I'd like to do is have a controller that connects to my mail box, via POP3 or IMAP, and retrieves the message, parses it then removes it from the server.

Piping mail from postfix/etc isn't going to work on my server setup.

Any suggestions would be immensely helpful.

Thanks!

Buckshee answered 20/9, 2009 at 7:8 Comment(0)
G
23

http://ca.php.net/imap

$mb = imap_open("{host:port/imap}","username", "password" );

$messageCount = imap_num_msg($mb);
for( $MID = 1; $MID <= $messageCount; $MID++ )
{
   $EmailHeaders = imap_headerinfo( $mb, $MID );
   $Body = imap_fetchbody( $mb, $MID, 1 );
   doSomething( $EmailHeaders, $Body );
}
Gastrotrich answered 20/9, 2009 at 7:22 Comment(1)
Really helpful, I was actually looking for something like this, pretty much works but still cant fetch/display content of the email ....Wooer
M
0

For a more independent approach you could build a Third party plugin with Zend framework (https://docs.zendframework.com/zend-mail/read/). I have used their ACL modules within Codeigniter and is a good way of getting the best of both frameworks.

This also allows you to parse the emails and extract attachments etc.

Mcgaw answered 7/12, 2017 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.