POP3/IMAP library for CodeIgniter
I was looking for POP3/IMAP library to read and delete emails from POP3/IMAP accounts but one I found on CodeIgniter forums was quite buggy. Fortunately I noticed this post on Reddit which featured Flourish PHP “unframework” and it’s fMailbox class.
I tried to run fMailbox class stand-alone and it worked quite well, so I decided to use it on my CodeIgniter application. I had to change how this class is initiated to use it as regular CodeIgniter library. Also in some places I had to replace Flourish exceptions with CodeIgniter’s error handling.
So, this is how you initiate library with just required parameters:
1 2 3 4 5 6 | $config['type'] = 'imap'; $config['host'] = 'mail.example.com'; $config['username'] = 'info@example.com'; $config['password'] = 'letsplay'; $this->load->library('mailbox', $config); |
More options are available:
1 2 3 4 5 6 7 8 9 | $config['type'] = 'imap'; $config['host'] = 'mail.example.com'; $config['username'] = 'info@example.com'; $config['password'] = 'letsplay'; $config['port'] = 993; $config['secure'] = TRUE; $config['timeout'] = 5; $this->load->library('mailbox', $config); |
And this is how you call methods:
1 | $messages = $this->mailbox->listMessages(10); |
So it works basically as documented here, but you have to pass initial arguments as array. Hope someone will find it useful, here’s the download, just copy Mailbox.php to your “libraries” directory and you should be good to go.