PHP code example of rochasmarcelo / emailmd

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

    

rochasmarcelo / emailmd example snippets



    il
    $MailBox = EmailMD\MailBoxFactory::gmail(
        '[email protected]',
        'yourpassword'
    );

    $MailBox->reverse();//Newest message first
    $MailBox->filterSince(new DateTime());//Just message recieved today
    //Get messages
    foreach ( $MailBox as $messageNumber => $message ) {
        echo 'Message number: ' . $messageNumber . PHP_EOL;
        echo $message->getSubject() . PHP_EOL;
    }


    tance
    $MailBox = EmailMD\MailBoxFactory::gmail(
        '[email protected]',
        'yourpassword'
    );

    //Get some messages
    $limit = 10;
    foreach ( $MailBox as $messageNumber => $message ) {
        echo 'Message number: ' . $messageNumber . PHP_EOL;
        echo $message->getSubject() . PHP_EOL;
        $limit--;
        if ( $limit < 1 ) {
            break;
        }
    }


    tance
    $MailBox = EmailMD\MailBoxFactory::gmail(
        '[email protected]',
        'yourpassword'
    );

    //Since today
    $MailBox->filterSince(new DateTime());
    foreach ( $MailBox as $messageNumber => $message ) {
        echo 'Message number: ' . $messageNumber . PHP_EOL;
        echo $message->getSubject() . PHP_EOL;
    }
    //Since yesterday
    $MailBox->filterSince(new DateTime('-1 days'));
    foreach ( $MailBox as $messageNumber => $message ) {
        echo 'Message number: ' . $messageNumber . PHP_EOL;
        echo $message->getSubject() . PHP_EOL;
    }


    tance
    $MailBox = EmailMD\MailBoxFactory::gmail(
        '[email protected]',
        'yourpassword'
    );
    $MailBox->reverse();//Now we get the newest first

    //Since today
    $MailBox->filterSince(new DateTime());
    foreach ( $MailBox as $messageNumber => $message ) {
        echo 'Message number: ' . $messageNumber . PHP_EOL;
        echo $message->getSubject() . PHP_EOL;
    }
    $MailBox->reverse();//Now we get the oldest first