PHP Classes

Email Reader: Retrieve email messages from POP3 or IMAP mailbox

Recommend this page to a friend!
  Info   View files Example   View files View files (14)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (3 months ago) RSS 2.0 feedStarStarStar 59%Total: 605 All time: 5,163 This week: 96Up
Version License PHP version Categories
emailmd 1.11MIT/X Consortium ...5.3Email, PHP 5
Description 

Author

This package can retrieve email messages from POP3 or IMAP mailbox.

It can connect to a given POP3 or IMAP server and retrieve email messages on a given mailbox. It provides shortcut functions to connect to Gmail, Yahoo or Hotmail mailboxes.

It can filter messages by date and sort the returned message listing, and retrieve the details of each message.

Picture of Marcelo Rocha
  Performance   Level  
Name: Marcelo Rocha <contact>
Classes: 1 package by
Country: Brazil Brazil
Age: 34
All time rank: 3038220 in Brazil Brazil
Week rank: 321 Up24 in Brazil Brazil Up

Example

<?php
   
require_once '../vendor/autoload.php';
   
//Gmail
   
$MailBox = EmailMD\MailBoxFactory::gmail(
       
'yourusername@gmail.com',
       
'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;
    }
?>

<?php
   
require_once '../vendor/autoload.php';
   
//Getting just some messages
    //instance
   
$MailBox = EmailMD\MailBoxFactory::gmail(
       
'yourusername@gmail.com',
       
'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;
        }
    }
?>

<?php
   
require_once '../vendor/autoload.php';
   
//Getting messages recieved since a specific date
    //instance
   
$MailBox = EmailMD\MailBoxFactory::gmail(
       
'yourusername@gmail.com',
       
'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;
    }
?>

<?php
   
require_once '../vendor/autoload.php';
   
//Getting messages in reverse order
    //instance
   
$MailBox = EmailMD\MailBoxFactory::gmail(
       
'yourusername@gmail.com',
       
'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
?>


Details

EmailMD

A PHP library to read e-mails.

Install with composer

{
    "require": {
        "rochasmarcelo/emailmd": "dev-master"
    }
}

Requirements

  • PHP 5.3.*
  • Imap extension

Example

Getting a MailBox instance

<?php
    require_once 'vendor/autoload.php';
    //Gmail
    $MailBox = EmailMD\MailBoxFactory::gmail(
        'yourusername@gmail.com',
        'yourpassword'
    );

    //Hotmail / live / msn
    $MailBox = EmailMD\MailBoxFactory::live(
        'yourusername@live.com',
        'yourpassword'
    );

    //Yahoo
    $MailBox = EmailMD\MailBoxFactory::yahoo(
        'yourusername@yahoo.com',
        'yourpassword'
    );

    //Other pop3
    $MailBox = EmailMD\MailBoxFactory::make(
        '{localhost:110/pop3}INBOX',
        'yourusername@site.com',
        'yourpassword'
    );

    //Other imap
    $MailBox = EmailMD\MailBoxFactory::make(
        '{localhost:993/imap/ssl}INBOX',
        'yourusername@site.com',
        'yourpassword'
    );
?>

Basic usage

<?php
    require_once 'vendor/autoload.php';
    //Gmail
    $MailBox = EmailMD\MailBoxFactory::gmail(
        'yourusername@gmail.com',
        '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;
    }
?>

Getting just some messages

<?php
    require_once 'vendor/autoload.php';
    //instance
    $MailBox = EmailMD\MailBoxFactory::gmail(
        'yourusername@gmail.com',
        '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;
        }
    }
?>

Getting messages recieved since a specific date

<?php
    require_once 'vendor/autoload.php';
    //instance
    $MailBox = EmailMD\MailBoxFactory::gmail(
        'yourusername@gmail.com',
        '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;
    }
?>

Getting messages in reverse order

By default the mailbox will return the oldest messages first. But sometimes we need to get the newest messages first, to do so we need to call the "MailBox::reverse" method one time.

<?php
    require_once 'vendor/autoload.php';
    //instance
    $MailBox = EmailMD\MailBoxFactory::gmail(
        'yourusername@gmail.com',
        '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
?>

  Files folder image Files  
File Role Description
Files folder imageexamples (2 files)
Files folder imagesrc (1 directory)
Files folder imagetests (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Auxiliary data
Accessible without login Plain text file _config.yml Data Auxiliary data

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file basic.php Example Basic usage
  Accessible without login Plain text file full.php Example Usage

  Files folder image Files  /  src  
File Role Description
Files folder imageEmailMD (4 files, 1 directory)

  Files folder image Files  /  src  /  EmailMD  
File Role Description
Files folder imageEntity (1 file)
  Plain text file EntityFactory.php Class Class source
  Plain text file ImapStream.php Class Class source
  Plain text file MailBox.php Class Class source
  Plain text file MailBoxFactory.php Class Class source

  Files folder image Files  /  src  /  EmailMD  /  Entity  
File Role Description
  Plain text file Message.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageEmailMD (1 directory)

  Files folder image Files  /  tests  /  EmailMD  
File Role Description
Files folder imageCase (1 file, 1 directory)

  Files folder image Files  /  tests  /  EmailMD  /  Case  
File Role Description
Files folder imageEntity (1 file)
  Accessible without login Plain text file EntityFactoryTestCase.php Test Unit test script

  Files folder image Files  /  tests  /  EmailMD  /  Case  /  Entity  
File Role Description
  Accessible without login Plain text file MessageTest.php Test Unit test script

 Version Control Unique User Downloads Download Rankings  
 85%
Total:605
This week:0
All time:5,163
This week:96Up
 User Ratings  
 
 All time
Utility:66%StarStarStarStar
Consistency:66%StarStarStarStar
Documentation:66%StarStarStarStar
Examples:66%StarStarStarStar
Tests:66%StarStarStarStar
Videos:-
Overall:59%StarStarStar
Rank:1243