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

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

wisesight/imap
==============

Object-oriented IMAP for PHP - Modified by Wisesight

1.11.0(5y ago)05.0kMITPHPPHP ^7.3 || ^8.0

Since Nov 22Pushed 5y agoCompare

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

READMEChangelog (1)Dependencies (6)Versions (46)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 ddeboer/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 Wisesight\Imap\Server;

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

// $connection is instance of \Wisesight\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 \Wisesight\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 \Wisesight\Imap\Message
}
```

#### Searching for Messages

[](#searching-for-messages)

```
use Wisesight\Imap\SearchExpression;
use Wisesight\Imap\Search\Email\To;
use Wisesight\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 [\\Wisesight\\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 \Wisesight\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

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 57.8% 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 ~61 days

Recently: every ~115 days

Total

44

Last Release

1906d ago

Major Versions

0.5.2 → 1.0.02017-10-04

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

1.0.0PHP ^7.0

1.6.0PHP ^7.1

1.10.0PHP ^7.2

1.11.0PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/52404809?v=4)[Gorlph](/maintainers/thanathip-wisesight)[@thanathip-wisesight](https://github.com/thanathip-wisesight)

---

Top Contributors

[![Slamdunk](https://avatars.githubusercontent.com/u/152236?v=4)](https://github.com/Slamdunk "Slamdunk (293 commits)")[![ddeboer](https://avatars.githubusercontent.com/u/89267?v=4)](https://github.com/ddeboer "ddeboer (157 commits)")[![thanathip-wisesight](https://avatars.githubusercontent.com/u/52404809?v=4)](https://github.com/thanathip-wisesight "thanathip-wisesight (5 commits)")[![trungpv1601](https://avatars.githubusercontent.com/u/25415217?v=4)](https://github.com/trungpv1601 "trungpv1601 (5 commits)")[![wujku](https://avatars.githubusercontent.com/u/1288915?v=4)](https://github.com/wujku "wujku (5 commits)")[![trungpv93](https://avatars.githubusercontent.com/u/7832459?v=4)](https://github.com/trungpv93 "trungpv93 (4 commits)")[![krzysiekpiasecki](https://avatars.githubusercontent.com/u/4520629?v=4)](https://github.com/krzysiekpiasecki "krzysiekpiasecki (3 commits)")[![xelan](https://avatars.githubusercontent.com/u/5080535?v=4)](https://github.com/xelan "xelan (3 commits)")[![mvar](https://avatars.githubusercontent.com/u/1286752?v=4)](https://github.com/mvar "mvar (3 commits)")[![FlashWS](https://avatars.githubusercontent.com/u/9982293?v=4)](https://github.com/FlashWS "FlashWS (2 commits)")[![pepamartinec](https://avatars.githubusercontent.com/u/271753?v=4)](https://github.com/pepamartinec "pepamartinec (2 commits)")[![pyatnitsev](https://avatars.githubusercontent.com/u/4361764?v=4)](https://github.com/pyatnitsev "pyatnitsev (2 commits)")[![LeadTechVisas](https://avatars.githubusercontent.com/u/44460455?v=4)](https://github.com/LeadTechVisas "LeadTechVisas (2 commits)")[![trizz](https://avatars.githubusercontent.com/u/832056?v=4)](https://github.com/trizz "trizz (2 commits)")[![nikoskip](https://avatars.githubusercontent.com/u/1230033?v=4)](https://github.com/nikoskip "nikoskip (2 commits)")[![boekkooi](https://avatars.githubusercontent.com/u/399895?v=4)](https://github.com/boekkooi "boekkooi (2 commits)")[![cabloo](https://avatars.githubusercontent.com/u/229041?v=4)](https://github.com/cabloo "cabloo (2 commits)")[![OskarStark](https://avatars.githubusercontent.com/u/995707?v=4)](https://github.com/OskarStark "OskarStark (1 commits)")[![burci](https://avatars.githubusercontent.com/u/864531?v=4)](https://github.com/burci "burci (1 commits)")[![cordoval](https://avatars.githubusercontent.com/u/328359?v=4)](https://github.com/cordoval "cordoval (1 commits)")

---

Tags

mailemailimap

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[ddeboer/imap

Object-oriented IMAP for PHP

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

MIME email message parser

54149.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

226.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)
