PHP code example of aymanrb / php-mail-filters
1. Go to this page and download the library: Download aymanrb/php-mail-filters library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aymanrb / php-mail-filters example snippets
//Step 1: Build the filter(s) with Criteria and Actions
$mailFilter = new Filter();
$mailFilter
->setName('Move mails that contains "RID" in its subject to Tagged folder')
->addCriterion(new SubjectCriterion('*RID*'))
->addAction(new MoveMailAction('Tagged'));
$mailFilters = new MailFilter();
$mailFilters->addFilter($mailFilter);
// Step 2: Read the message
$mailbox = new PhpImap\Mailbox(
'{imap.example.org:993/imap/ssl}INBOX',
'[email protected]',
'SecretPassword'
);
$mailMessageAdapter = new MailFilters\Adapters\BarbushinImap\MessageAdapter($mailbox);
$messageIds = $mailbox->searchMailbox('ALL');
$firstMessage = $mailbox->getMail();
// Step 3: Apply filters to message
$mailMessageAdapter->setMessage($firstMessage)
$mailFilters->applyFilters($mailMessageAdapter);