PHPackages                             hrodrigues1984/imap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. hrodrigues1984/imap

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

hrodrigues1984/imap
===================

Object-oriented IMAP for PHP

0.5.32(9y ago)013MITPHPPHP &gt;=5.5

Since Nov 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/hrodrigues1984/imap)[ Packagist](https://packagist.org/packages/hrodrigues1984/imap)[ RSS](/packages/hrodrigues1984-imap/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (13)Used By (0)

IMAP library
============

[](#imap-library)

[![Build Status](https://camo.githubusercontent.com/f885892bbda0d92cde4499eb216ffba389a093bfd45fb36e3aa4581e9c3a6f67/68747470733a2f2f7472617669732d63692e6f72672f68726f64726967756573313938342f696d61702e7376673f6272616e63683d6d617374657226666f726d61743d666c6174)](https://travis-ci.org/hrodrigues1984/imap)[![Latest Stable Version](https://camo.githubusercontent.com/a6a7228b9a44eb9e972e923c1b4dd38a4d45ffc56e31ddab42893f8ea822f915/68747470733a2f2f706f7365722e707567782e6f72672f68726f64726967756573313938342f696d61702f762f737461626c65)](https://packagist.org/packages/hrodrigues1984/imap)[![Total Downloads](https://camo.githubusercontent.com/4140ceded03ec4616aba39bfb4ce2681ff3777777c86cc36f202020c87e9821c/68747470733a2f2f706f7365722e707567782e6f72672f68726f64726967756573313938342f696d61702f646f776e6c6f616473)](https://packagist.org/packages/hrodrigues1984/imap)[![Latest Unstable Version](https://camo.githubusercontent.com/23fcbe9a1d7cb5c9b9cf04dd7442ceaef4514b3200b0e681a22f1179526a3199/68747470733a2f2f706f7365722e707567782e6f72672f68726f64726967756573313938342f696d61702f762f756e737461626c65)](https://packagist.org/packages/hrodrigues1984/imap)[![License](https://camo.githubusercontent.com/59002204f86f4d9f43923a4856c9da4cbf501dee9b507260a6fc917f37af3e89/68747470733a2f2f706f7365722e707567782e6f72672f68726f64726967756573313938342f696d61702f6c6963656e73653f666f726d61743d666c6174)](https://packagist.org/packages/hrodrigues1984/imap)

A PHP 5.5+ library to read and process e-mails over IMAP.

Installation
------------

[](#installation)

Make sure the [PHP IMAP extension](http://php.net/manual/en/book.imap.php)is installed. For instance on Debian:

The recommended way to install the IMAP library is through [Composer](http://getcomposer.org):

```
$ composer require hrodrigues1984/imap
```

This command requires you to have Composer installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md)of the Composer documentation.

Usage
-----

[](#usage)

### Connect and Authenticate

[](#connect-and-authenticate)

```
use Ddeboer\Imap\Server;

$server = new Server('imap.mail.com');

// $connection is instance of \Ddeboer\Imap\Connection
$connection = $server->authenticate('my_username', 'my_password');
```

#### Options

[](#options)

You can specify port, [flags and parameters](http://php.net/manual/en/function.imap-open.php)to the server:

```
$server = new Server(
    $hostname, // required
    $port,     // defaults to 993
    $flags,    // defaults to '/imap/ssl/validate-cert'
    $parameters
);
```

### Mailboxes

[](#mailboxes)

Retrieve mailboxes (also known as mail folders) from the mail server and iterate over them:

```
$mailboxes = $connection->getMailboxes();

foreach ($mailboxes as $mailbox) {
    // $mailbox is instance of \Ddeboer\Imap\Mailbox
    printf('Mailbox %s has %s messages', $mailbox->getName(), $mailbox->count());
}
```

Or retrieve a specific mailbox:

```
$mailbox = $connection->getMailbox('Inbox');
```

Delete a mailbox:

```
$mailbox->delete();
```

### Messages

[](#messages)

Retrieve messages (e-mails) from a mailbox and iterate over them:

```
$messages = $mailbox->getMessages();

foreach ($messages as $message) {
    // $message is instance of \Ddeboer\Imap\Message
}
```

#### Searching for Messages

[](#searching-for-messages)

```
use Ddeboer\Imap\SearchExpression;
use Ddeboer\Imap\Search\Email\To;
use Ddeboer\Imap\Search\Text\Body;

$search = new SearchExpression();
$search->addCondition(new To('me@here.com'))
    ->addCondition(new Body('contents'))
;

$messages = $mailbox->getMessages($search);
```

#### Message Properties and Operations

[](#message-properties-and-operations)

Get message number and unique [message id](http://en.wikipedia.org/wiki/Message-ID)in the form &lt;...&gt;:

```
$message->getNumber();
$message->getId();
```

Get other message properties:

```
$message->getSubject();
$message->getFrom();
$message->getTo();
$message->getDate();
$message->isAnswered();
$message->isDeleted();
$message->isDraft();
$message->isSeen();
```

Get message headers as a [\\Ddeboer\\Imap\\Message\\Headers](/src/Ddeboer/Imap/Message/Headers.php) object:

```
$message->getHeaders();
```

Get message body as HTML or plain text:

```
$message->getBodyHtml();
$message->getBodyText();
```

Reading the message body marks the message as seen. If you want to keep the message unseen:

```
$message->keepUnseen()->getBodyHtml();
```

Move a message to another mailbox:

```
$mailbox = $connection->getMailbox('another-mailbox');
$message->move($mailbox);
```

Deleting messages:

```
$mailbox->getMessage(1)->delete();
$mailbox->getMessage(2)->delete();
$mailbox->expunge();
```

### Message Attachments

[](#message-attachments)

Get message attachments (both inline and attached) and iterate over them:

```
$attachments = $message->getAttachments();

foreach ($attachments as $attachment) {
    // $attachment is instance of \Ddeboer\Imap\Message\Attachment
}
```

Download a message attachment to a local file:

```
// getDecodedContent() decodes the attachment’s contents automatically:
file_put_contents(
    '/my/local/dir/' . $attachment->getFilename(),
    $attachment->getDecodedContent()
);
```

Running the Tests
-----------------

[](#running-the-tests)

If you have your own IMAP (test) account, you can run the tests locally by providing your IMAP (e.g., Email Provider) credentials:

```
$ composer install --dev
$ EMAIL_USERNAME="your_username" EMAIL_PASSWORD="your_password" EMAIL_SERVER="imap.mail.com" vendor/bin/phpunit
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~120 days

Recently: every ~193 days

Total

11

Last Release

3392d ago

PHP version history (2 changes)0.5.0PHP &gt;=5.4.0

0.5.3PHP &gt;=5.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/6227379fca0ab0e51f6f1694fff96a2d7a09ca52fdb38446073b5782c95e4228?d=identicon)[hrodrigues1984](/maintainers/hrodrigues1984)

---

Top Contributors

[![ddeboer](https://avatars.githubusercontent.com/u/89267?v=4)](https://github.com/ddeboer "ddeboer (154 commits)")[![hrodrigues1984](https://avatars.githubusercontent.com/u/8711911?v=4)](https://github.com/hrodrigues1984 "hrodrigues1984 (8 commits)")[![krzysiekpiasecki](https://avatars.githubusercontent.com/u/4520629?v=4)](https://github.com/krzysiekpiasecki "krzysiekpiasecki (3 commits)")[![mvar](https://avatars.githubusercontent.com/u/1286752?v=4)](https://github.com/mvar "mvar (3 commits)")[![xelan](https://avatars.githubusercontent.com/u/5080535?v=4)](https://github.com/xelan "xelan (3 commits)")[![boekkooi](https://avatars.githubusercontent.com/u/399895?v=4)](https://github.com/boekkooi "boekkooi (2 commits)")[![nikoskip](https://avatars.githubusercontent.com/u/1230033?v=4)](https://github.com/nikoskip "nikoskip (2 commits)")[![pepamartinec](https://avatars.githubusercontent.com/u/271753?v=4)](https://github.com/pepamartinec "pepamartinec (2 commits)")[![joserobleda](https://avatars.githubusercontent.com/u/1263865?v=4)](https://github.com/joserobleda "joserobleda (1 commits)")[![oliverkaiser](https://avatars.githubusercontent.com/u/2995870?v=4)](https://github.com/oliverkaiser "oliverkaiser (1 commits)")[![racztiborzoltan](https://avatars.githubusercontent.com/u/1519490?v=4)](https://github.com/racztiborzoltan "racztiborzoltan (1 commits)")[![abhinavkumar940](https://avatars.githubusercontent.com/u/1189133?v=4)](https://github.com/abhinavkumar940 "abhinavkumar940 (1 commits)")[![ysramirez](https://avatars.githubusercontent.com/u/5892242?v=4)](https://github.com/ysramirez "ysramirez (1 commits)")[![aeyoll](https://avatars.githubusercontent.com/u/1472285?v=4)](https://github.com/aeyoll "aeyoll (1 commits)")[![burci](https://avatars.githubusercontent.com/u/864531?v=4)](https://github.com/burci "burci (1 commits)")[![cidtal](https://avatars.githubusercontent.com/u/103543376?v=4)](https://github.com/cidtal "cidtal (1 commits)")[![cmoralesweb](https://avatars.githubusercontent.com/u/5377322?v=4)](https://github.com/cmoralesweb "cmoralesweb (1 commits)")[![cordoval](https://avatars.githubusercontent.com/u/328359?v=4)](https://github.com/cordoval "cordoval (1 commits)")[![huglester](https://avatars.githubusercontent.com/u/150731?v=4)](https://github.com/huglester "huglester (1 commits)")[![jamesiarmes](https://avatars.githubusercontent.com/u/1030345?v=4)](https://github.com/jamesiarmes "jamesiarmes (1 commits)")

---

Tags

mailemailimap

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hrodrigues1984-imap/health.svg)

```
[![Health](https://phpackages.com/badges/hrodrigues1984-imap/health.svg)](https://phpackages.com/packages/hrodrigues1984-imap)
```

###  Alternatives

[ddeboer/imap

Object-oriented IMAP for PHP

9194.0M14](/packages/ddeboer-imap)[zbateson/mail-mime-parser

MIME email message parser

54651.9M86](/packages/zbateson-mail-mime-parser)[henrique-borba/php-sieve-manager

A modern (started in 2022) PHP library for the ManageSieve protocol (RFC5804) to create/edit Sieve scripts (RFC5228). Used by Cypht Webmail.

28137.9k3](/packages/henrique-borba-php-sieve-manager)[opcodesio/mail-parser

Parse emails without the mailparse extension

228.1M9](/packages/opcodesio-mail-parser)[benhall14/php-imap-reader

A PHP class that makes working with IMAP in PHP simple.

3518.7k](/packages/benhall14-php-imap-reader)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
