PHP code example of mkardakov / mail-reader

1. Go to this page and download the library: Download mkardakov/mail-reader 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/ */

    

mkardakov / mail-reader example snippets




// Setup necessary connection params
$config = new \Mails\Imap\Config();
$config->setHost('imap.gmail.com')
    ->setPort(993)
    ->setSsl(true)
    ->setUser('[email protected]')
    ->setPass('password');
    
// instantiate mailer service
$mailer = (new \Mails\MailKit())->create($config);

// Create filter for inbox letters
$criteria = new \Mails\Search\SearchCriteria();
$criteria->setFrom('[email protected]')->setBody('Hi, ');
// Create sort rule
// Sort Params must be valid constants from imap extension
//http://php.net/manual/ru/function.imap-sort.php#refsect1-function.imap-sort-parameters
 $sort = new \Mails\Sort\Sorter();
 $sort->setDirection(\Mails\Sort\Sorter::ASC)->setSortParam(SORTARRIVAL);
// Get \Generator
$emails = $mailer->getInbox($criteria, $sort);
foreach ($emails as $mail) {
    echo $letter->getHeaders()->getSubject();
    echo $letter->getBody()->getHTML();
}