There is no license information available for the latest version (v0.0.1-beta) of this package.

A library to help you create Gmail like mail filters in your PHP Application

v0.0.1-beta 2018-09-17 13:50 UTC


This is a PHP package that enables you to create handy filtering features on E-mail messages utilizing the PHP IMAP extension. The library is based on ddeboer/imap

With this library you can implement something similar to that of Gmail filters option in your PHP Application.


  • Apply filters your E-mail messages by setting criteria over the following fields:

    • To
    • All Recipients (To, Cc, Bcc)
    • Subject
    • From
    • Body Text
    • Attachments
  • Take one of the following actions based on matched filters:

    • Delete message from your mailbox.
    • Move the message to a different mail folder.
    • Copy the message to another mail folder.
    • Return user specified variables.
    • Mark message status (Read, Unread and Important)


//prepare the criteria
$subjectContainsRidCriterion = (new SubjectCriterion())->setValues('*RID*');

//prepare the actions
$returnValuesAction = new ReturnValuesAction(['specialIdSubject' => true]);
$moveToFolderAction = new MoveMailAction(
   [ActionsConstantsInterface::PARAM_DESTINATION_DIRECTORY => "New Mail Folder"]

//build the filter
$mailFilter = new Filter();
   ->setName('Mails that contains an RID in the subject')

$mailFilters = new MailFilter();

$server = new Server($config['imap_connection']['imap_server']);
$connection = $server->authenticate($config['imap_connection']['username'], $config['imap_connection']['password']);
$mailbox = $connection->getMailbox('INBOX');

$messages = $mailbox->getMessages();


if ($mailFilters->isFilterMatched()) {

The above example will check if the given email contains "RID" in its subject and move the message to a new MailBox "New Mail Folder" and print: Array([specialIdSubject] => 1)

In Progress (Unfinished work):
  • Adding a 'Bounce' or 'Forward' mail "Action"
Future Plans:
  • Adding tests to the library