PHPackages                             pedrofornaza/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. pedrofornaza/imap

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

pedrofornaza/imap
=================

Object-oriented IMAP for PHP

0.5.2(10y ago)0251MITPHPPHP &gt;=5.4.0

Since Nov 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/pedrofornaza/imap)[ Packagist](https://packagist.org/packages/pedrofornaza/imap)[ RSS](/packages/pedrofornaza-imap/feed)WikiDiscussions master Synced 1mo ago

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

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

[](#imap-library)

[![Build Status](https://camo.githubusercontent.com/d11de5bf96e88f5f56560e50fe981c02487faa0ce1640511b1b33ba0de740884/68747470733a2f2f7472617669732d63692e6f72672f646465626f65722f696d61702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ddeboer/imap)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1c992d9bbb84a34b657f0adc908bc57166a4ef55dd0d659f0905331464928b9b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646465626f65722f696d61702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ddeboer/imap/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/b992f5550c58f147803da18c0a4d4d0699c4bc957375f739320d80a541655026/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646465626f65722f696d61702f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ddeboer/imap/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/60410c03ccb8f20e6e36c399486becbf4ff915baed950fd98a1c9346793d5ca7/68747470733a2f2f706f7365722e707567782e6f72672f646465626f65722f696d61702f762f737461626c652e737667)](https://packagist.org/packages/ddeboer/imap)

A PHP 5.4+ 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:

```
# apt-get install php5-imap
```

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

```
$ composer require pedrofornaza/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.gmail.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)

This library is functionally tested on [Travis CI](https://travis-ci.org/ddeboer/imap)against the Gmail IMAP server.

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

```
$ composer install --dev
$ EMAIL_USERNAME="your_username" EMAIL_PASSWORD="your_password" vendor/bin/phpunit
```

You can also set an `EMAIL_SERVER` variable, which defaults to `imap.gmail.com`:

```
$ EMAIL_USERNAME="your_username" EMAIL_PASSWORD="your_password" EMAIL_SERVER="imap.you.com" vendor/bin/phpunit
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.2% 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 ~105 days

Recently: every ~119 days

Total

8

Last Release

3811d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/655ecdafe55c4fe42a99e245005d23583bf1fd9656b6e4882c6d0339595963d9?d=identicon)[pedrofornaza](/maintainers/pedrofornaza)

---

Top Contributors

[![ddeboer](https://avatars.githubusercontent.com/u/89267?v=4)](https://github.com/ddeboer "ddeboer (154 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)")[![krzysiekpiasecki](https://avatars.githubusercontent.com/u/4520629?v=4)](https://github.com/krzysiekpiasecki "krzysiekpiasecki (3 commits)")[![pepamartinec](https://avatars.githubusercontent.com/u/271753?v=4)](https://github.com/pepamartinec "pepamartinec (2 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)")[![pedrofornaza](https://avatars.githubusercontent.com/u/1180994?v=4)](https://github.com/pedrofornaza "pedrofornaza (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/pedrofornaza-imap/health.svg)

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

###  Alternatives

[ddeboer/imap

Object-oriented IMAP for PHP

9153.9M11](/packages/ddeboer-imap)[zbateson/mail-mime-parser

MIME email message parser

53949.2M79](/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.

23125.7k2](/packages/henrique-borba-php-sieve-manager)[opcodesio/mail-parser

Parse emails without the mailparse extension

216.8M8](/packages/opcodesio-mail-parser)[benhall14/php-imap-reader

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

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

PHPackages © 2026

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