I write here what I learn

IMAPX is a PHP IMAP library

IMAPX is a PHP IMAP library

IMAPX is a library for reading email from server using the IMAP or POP3 protocol. You can use it in your any PHP project. IMAPX also works with Laravel 5 . Its a beta release. This library includes many convenience methods to help take the headache out of dealing with emails in PHP. If you have any issues or feature suggestions or fetch any problem please inform me.


Its strongly recommend to install php5-imap on your system. To install php5-imap on any debian based system run those command with your terminal

sudo apt-get install php5-imap

sudo php5enmod imap

sudo service apache2 restart

If confirm php5-imap on your system then download IMAPX from github and unzip it. Then linked with your project.

Install with Laravel 5

IMAPX also compatible with Laravel 5 . You can easily integrate IMAPX with Laravel project. Run this command with terminal

$ composer require nahidz/imapx

This command download this package in your project. After that you have to register this class in your config/app.php file. Open the file and add this line end of the providers array


Then run this command for move config file to config directory

$ php artisan vendor:publish

for that command imapx.php config file copy to config directory.

Thats it.


To use this package you have to config this. For simple php project open src/imapxPHP.php and set this data

private $driver			=	'imap'; 
private $hostname		=	''; 
private $username		=	''; 
private $password		=	'your-password';
private $ssl			=	true; 
private $novalidate		=	false; 

For laravel

Open config/imapx.php and set the desire value

return [
    'host'          	=>      '',

    'username'     	=>      '', 

    'password'      	=>      'your-password',

    'port'          	=>      993,

    'driver'        	=>      'imap', 

    'ssl'		=>	true, 

    'novalidate'	=>  	false, 

    'auto-connect'  	=> 	false  

After use this package please be sure to config this properly



require_once "path/to/imapxPHP.php";

$imap=new Imapx;



If you set auto-connect=true then you haven't to connect manually. Otherwise use connect() method.

use Nahidz\Imapx\Imapx;

public function inbox(Imapx $imap)
    $imap->connect(); // if auto-connect = false
    $inbox = $imap->getInbox();

Methods and Properties

array getInbox([int $page, [int $perPage, [array $sort]]]) here this method return an array and all parameters are optional

object readMail($messageId) here this method return an object of class and get a single param as messageId

here all of method depend of readMail() method

string getDate([$pattern]) this method return a string and get a date pattern as optional value. If there are no pattern it return Y-m-d format date

string getSubject() return a string

string getRecieverEmail() return a string

string getSenderName() return a string

string getSenderEmail() return a string

string getSenderLink([$class]) return string and get parameter as optional for html class name

boolean isSeen() return true/false

boolean isAnswered() return true/false

float getSize([$unit]) return float value and get a parameter as optional. its data unit. you can set mb(megabyte) or kb(kilobyte). default kb

string getBody([$displayType, [$decode]]) return a string and get two optional param. first is for display type (text or html) and second is for decode status [true/false]


$imap=new Imapx;

$msg = $imap->readMail(1);

echo '<h1>'.$msg->getSubject().'</h1>';
echo '<p>'.$msg->getBody('html', true).'</p>';


Thank you



Hello, there is the possibility of obtaining email attachments?


Hello, there is the possibility of obtaining email attachments?


We are working for it. Now you can not attach any file/s with email.

Thank you for using IMAPX :)

To make a comment you have to login