dev-master
9999999-devA PHP wrapper class for PHP's IMAP-related email handling functions.
MIT
The Requires
- php ^7.0
- ext-imap *
The Development Requires
by Paul P
php wrapper imap
A PHP wrapper class for PHP's IMAP-related email handling functions.
This library is an improvement of Jeff Geerling's project tailored specifically for my needs at the moment., (*1)
Keep in mind that this is still a work in progress so radical changes may occurr in time., (*2)
You can install this library via composer by running the command bellow or you can clone the repository., (*3)
composer require bigpaulie/imap
A mailbox in the context of this library is referring to a directory of your email account., (*4)
Connect to an IMAP account by creating a new Imap object with the required parameters:, (*5)
$host = 'imap.example.com'; $user = 'johndoe'; $pass = '12345'; $port = 993; $ssl = true; $folder = 'INBOX'; $server = new Imap($host, $user, $pass, $port, $ssl, $folder);
/** @var Mailbox $mailbox */ $mailbox = $server->getMailbox();
If you want to access another directory, (*6)
/** @var Mailbox $mailbox */ $mailbox = $server->getMailbox('SPAM');
/** @var array $info */ $info = $mailbox->getInfo();
/** @var Message[] $messages */ $messages = $mailbox->getMessages();
You can then iterate through the array of messages, (*7)
/** @var Message $message */ foreach ($messages as $message) { $subject = $message->getSubject(); $messageBody = $message->getBody(); }
You can obtain only certain messages if you want to., (*8)
Only undeleted messages, (*9)
/** @var Search $criteria */ $criteria = new Search(); $criteria->setCriteria(Search::UNDELETED); /** @var Message[] $messages */ $messages = $mailbox->getMessages($criteria);
You can add multiple search criterias for example :, (*10)
/** @var Search $criteria */ $criteria = new Search(); $criteria->setCriteria(Search::UNDELETED); $criteria->setCriteria(Search::FROM, "John Doe"); $criteria->setCriteria(Search::KEYWORD, "candy"); /** @var Message[] $messages */ $messages = $mailbox->getMessages($criteria);
Search criterias can be chained together:, (*11)
/** @var Search $criteria */ $criteria = new Search(); $criteria->setCriteria(Search::UNDELETED) ->setCriteria(Search::FROM, "John Doe") ->setCriteria(Search::KEYWORD, "candy"); /** @var Message[] $messages */ $messages = $mailbox->getMessages($criteria);
You can move messages from one mailbox to another very easily, (*12)
if ($mailbox->moveMessage($message, 'SPAM')) { echo "Message moved successfuly"; }
Copying messages is as easy as moving them, (*13)
if ($mailbox->copyMessage($message, 'SPAM')) { echo "Message moved successfuly"; }
$mailbox->deleteMessage($message);
$server->disconnect();
If you want to make a contribution and improve the library or you noticed a bug you are more than welcome to do so., (*14)
For contributors just fork, code and submit a pull request., (*15)
Please maintain the coding style and testing patterns., (*16)
A PHP wrapper class for PHP's IMAP-related email handling functions.
MIT
php wrapper imap