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

ActiveLibrary

evoweb/php-imap
===============

Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)

00PHPCI passing

Since Apr 4Pushed 1mo agoCompare

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

READMEChangelogDependenciesVersions (2)Used By (0)

PHP IMAP
========

[](#php-imap)

Based on works until December 2022 in [barbushin/php-imap](https://github.com/barbushin/php-imap) with merged pull requests
---------------------------------------------------------------------------------------------------------------------------

[](#based-on-works-until-december-2022-in-barbushinphp-imap-with-merged-pull-requests)

[![GitHub release](https://camo.githubusercontent.com/8a8d0b0209fc8dc0ad6cf049517241a4dee94cb0bd25f4baf610396363d6e68c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f65766f7765622f7068702d696d6170)](https://packagist.org/packages/evoweb/php-imap)[![Supported PHP Version](https://camo.githubusercontent.com/1672c6f3893b29ed5b283e7a5447742965e8cf9637011eb2f3dc6b655bd9be71/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f65766f7765622f7068702d696d6170)](README.md)[![Software License](https://camo.githubusercontent.com/88e1dabf4d223df0950e0985948e231325fefca9fa7fe9e446cf8b1c5e9d9e47/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e)](LICENSE)[![Downloads Packagist](https://camo.githubusercontent.com/a8a55a4c34e1a7d42d77b6e8b3e5cf6805f442daa45e37b3042e30d4a6d3ea75/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f65766f7765622f7068702d696d6170)](https://packagist.org/packages/evoweb/php-imap)

[![CI PHP Unit Tests](https://github.com/evoweb/php-imap/actions/workflows/php_unit_tests.yml/badge.svg?branch=master)](https://github.com/evoweb/php-imap/actions/workflows/php_unit_tests.yml)[![CI PHP Static Analysis](https://github.com/evoweb/php-imap/actions/workflows/php_static_analysis.yml/badge.svg?branch=master)](https://github.com/evoweb/php-imap/actions/workflows/php_static_analysis.yml)[![CI PHP Code Coverage](https://github.com/evoweb/php-imap/actions/workflows/php_code_coverage.yml/badge.svg?branch=master)](https://github.com/evoweb/php-imap/actions/workflows/php_code_coverage.yml)

[![Maintainability](https://camo.githubusercontent.com/7b1907af771dd6aad49df80e270ca73800206f5f016fceed9ff84d4436530f17/68747470733a2f2f716c74792e73682f67682f65766f7765622f70726f6a656374732f7068702d696d61702f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/garbast/projects/php-imap)[![Code Coverage](https://camo.githubusercontent.com/f48402f4f91cf2dc5d9141be53273375abdf173ab2a065ab740cae40b08a7701/68747470733a2f2f716c74792e73682f67682f65766f7765622f70726f6a656374732f7068702d696d61702f636f7665726167652e737667)](https://qlty.sh/gh/garbast/projects/php-imap)

Initially released in December 2012, the PHP IMAP Mailbox is a powerful and open source library to connect to a mailbox by POP3, IMAP and NNTP using the PHP IMAP extension. This library allows you to fetch emails from your email server. Extend the functionality or create powerful web applications to handle your incoming emails.

### Features

[](#features)

- Connect to mailbox by POP3/IMAP/NNTP, using [PHP IMAP extension](http://php.net/manual/book.imap.php)
- Get emails with attachments and inline images
- Get emails filtered or sorted by custom criteria
- Mark emails as seen/unseen
- Delete emails
- Manage mailbox folders

### Requirements

[](#requirements)

PHP Versionphp-imap Versionphp-imap status5.63.xEnd of life7.03.xEnd of life7.13.xEnd of life7.23.x, 4.xEnd of life7.33.x, 4.xEnd of life7.4&gt;3.0.33, 4.x, 5.xEnd of life8.0&gt;3.0.33, 4.x, 5.xEnd of life8.1&gt;4.3.0, 5.xEnd of life8.26.xActive support8.36.xActive support8.46.xActive support8.56.xActive support- PHP `fileinfo` extension must be present; so make sure this line is active in your php.ini: `extension=php_fileinfo.dll`
- PHP `iconv` extension must be present; so make sure this line is active in your php.ini: `extension=php_iconv.dll`
- PHP `imap` extension must be present; so make sure this line is active in your php.ini: `extension=php_imap.dll`
- PHP `mbstring` extension must be present; so make sure this line is active in your php.ini: `extension=php_mbstring.dll`
- PHP `json` extension must be present; so make sure this line is active in your php.ini: `extension=json.dll`

### Installation by Composer

[](#installation-by-composer)

Install the [latest available release](https://github.com/evoWeb/php-imap/releases):

```
$ composer require evoWeb/php-imap

```

Install the latest available and stable source code from `develop`, which may not be released / tagged yet:

```
$ composer require evoWeb/php-imap:dev-develop

```

### Run Tests

[](#run-tests)

Before you can run any tests you may need to run `composer install` to install all (development) dependencies.

#### Run all tests

[](#run-all-tests)

You can run all available tests by running the following command (inside the installed `php-imap` directory): `composer run tests`

#### Run only PHPUnit tests

[](#run-only-phpunit-tests)

You can run all PHPUnit tests by running the following command (inside the installed `php-imap` directory): `php vendor/bin/phpunit --testdox`

### Integration with frameworks

[](#integration-with-frameworks)

- Symfony -

### Getting Started Example

[](#getting-started-example)

Below, you'll find an example code how you can use this library. For further information and other examples, you may take a look at the [wiki](https://github.com/barbushin/php-imap/wiki).

By default, this library uses random filenames for attachments as identical file names from other emails would overwrite other attachments. If you want to keep the original file name, you can set the attachment filename mode to `true`, but then you also need to ensure, that those files don't get overwritten by other emails for example.

```
// Create PhpImap\Mailbox instance for all further actions
$mailbox = new PhpImap\Mailbox(
    '{imap.gmail.com:993/imap/ssl}INBOX', // IMAP server and mailbox folder
    'some@gmail.com', // Username for the before configured mailbox
    '*********', // Password for the before configured username
    __DIR__, // Directory, where attachments will be saved (optional)
    'UTF-8', // Server encoding (optional)
    true, // Trim leading/ending whitespaces of IMAP path (optional)
    false // Attachment filename mode (optional; false = random filename; true = original filename)
);

// set some connection arguments (if appropriate)
$mailbox->setConnectionArgs(
    CL_EXPUNGE // expunge deleted mails upon mailbox close
    | OP_SECURE // don't do non-secure authentication
);

try {
    // Get all emails (messages)
    // PHP.net imap_search criteria: https://php.net/manual/en/function.imap-search.php
    $mailsIds = $mailbox->searchMailbox('ALL');
} catch(PhpImap\Exceptions\ConnectionException $ex) {
    echo "IMAP connection failed: " . implode(",", $ex->getErrors('all'));
    die();
}

// If $mailsIds is empty, no emails could be found
if(!$mailsIds) {
    die('Mailbox is empty');
}

// Get the first message
// If '__DIR__' was defined in the first line, it will automatically
// save all attachments to the specified directory
$mail = $mailbox->getMail($mailsIds[0]);

// Show, if $mail has one or more attachments
echo "\nMail has attachments? ";
if($mail->hasAttachments()) {
    echo "Yes\n";
} else {
    echo "No\n";
}

// Print all information of $mail
print_r($mail);

// Print all attachments of $mail
echo "\n\nAttachments:\n";
print_r($mail->getAttachments());
```

Method `imap()` allows to call any [PHP IMAP function](https://www.php.net/manual/ref.imap.php) in a context of the instance. Example:

```
// Call imap_check() - see https://php.net/manual/function.imap-check.php
$info = $mailbox->imap('check');

// Show current time for the mailbox
$currentServerTime = isset($info->Date) && $info->Date ? date('Y-m-d H:i:s', strtotime($info->Date)) : 'Unknown';

echo $currentServerTime;
```

Some request require much time and resources:

```
// If you don't need to grab attachments you can significantly increase performance of your application
$mailbox->setAttachmentsIgnore(true);

// get the list of folders/mailboxes
$folders = $mailbox->getMailboxes('*');

// loop through mailboxes
foreach($folders as $folder) {

    // switch to particular mailbox
    $mailbox->switchMailbox($folder['fullpath']);

    // search in particular mailbox
    $mails_ids[$folder['fullpath']] = $mailbox->searchMailbox('SINCE "1 Jan 2018" BEFORE "28 Jan 2018"');
}

print_r($mails_ids);
```

### Upgrading from below 6.x

[](#upgrading-from-below-6x)

BREAKING: Before each method in Imap checked if it really got a connection handed. Now the functions are enforcing connection with typed arguments. You are still able to use Imap::EnsureConnection() yourself if you need to check your argument.

Functions are convertest to camel case:

- Imap::createmailbox -&gt; Imap::createMailbox (public)
- Imap::deletemailbox -&gt; Imap::deleteMailbox (public)
- Imap::EnsureConnection -&gt; Imap::ensureConnection (public)
- Imap::EnsureRange -&gt; Imap::ensureRange (private)
- Imap::EnsureResource -&gt; Imap::ensureResource (private)
- Imap::fetchbody -&gt; Imap::fetchBody (public)
- Imap::fetchheader -&gt; Imap::fetchHeader (public)
- Imap::fetchstructure -&gt; Imap::fetchStructure (public)
- Imap::getmailboxes -&gt; Imap::getMailboxes (public)
- Imap::getsubscribed -&gt; Imap::getSubscribed (public)
- Imap::fetch\_overview -&gt; Imap::fetchOverview (public)
- Imap::get\_quotaroot -&gt; Imap::getQuotaRoot (public)
- Imap::HandleErrors -&gt; Imap::handleErrors (private)
- Imap::mail\_compose -&gt; Imap::mailCompose (public)
- Imap::mail\_copy -&gt; Imap::mailCopy (public)
- Imap::mail\_move -&gt; Imap::mailMove (public)
- Imap::mailboxmsginfo -&gt; Imap::mailboxMsgInfo (public)
- Imap::num\_msg -&gt; Imap::numMsg (public)
- Imap::renamemailbox -&gt; Imap::renameMailbox (public)
- Imap::savebody -&gt; Imap::saveBody (public)
- Imap::clearflag\_full -&gt; Imap::clearFlagFull (public)
- Imap::setflag\_full -&gt; Imap::setFlagFull (public)
- Mailbox::lowercase\_mb\_list\_encodings -&gt; Mailbox::lowercaseMbListEncodings (protected)

### Upgrading from 3.x

[](#upgrading-from-3x)

Prior to 3.1, `Mailbox` used a "magic" method (`Mailbox::imap()`), with the class `Imap` now performing its purpose to call many `imap_*` functions with automated string encoding/decoding of arguments and return values:

Before:

```
    public function checkMailbox()
    {
        return $this->imap('check');
    }
```

After:

```
    public function checkMailbox(): object
    {
        return Imap::check($this->getImapStream());
    }
```

### Recommended

[](#recommended)

- Google Chrome extension [PHP Console](https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef)
- Google Chrome extension [JavaScript Errors Notifier](https://chrome.google.com/webstore/detail/javascript-errors-notifie/jafmfknfnkoekkdocjiaipcnmkklaajd)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance60

Regular maintenance activity

Popularity0

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/bb4dafa036924944329c38464e7ee805686072f4e630039a56a6e4e892765080?d=identicon)[garbast](/maintainers/garbast)

---

Top Contributors

[![bapcltd-marv](https://avatars.githubusercontent.com/u/46891309?v=4)](https://github.com/bapcltd-marv "bapcltd-marv (387 commits)")[![Sebbo94BY](https://avatars.githubusercontent.com/u/5154682?v=4)](https://github.com/Sebbo94BY "Sebbo94BY (193 commits)")[![barbushin](https://avatars.githubusercontent.com/u/683352?v=4)](https://github.com/barbushin "barbushin (148 commits)")[![garbast](https://avatars.githubusercontent.com/u/5036924?v=4)](https://github.com/garbast "garbast (113 commits)")[![quentinus95](https://avatars.githubusercontent.com/u/8060564?v=4)](https://github.com/quentinus95 "quentinus95 (13 commits)")[![ThomasLandauer](https://avatars.githubusercontent.com/u/1054469?v=4)](https://github.com/ThomasLandauer "ThomasLandauer (12 commits)")[![SRWieZ](https://avatars.githubusercontent.com/u/1408020?v=4)](https://github.com/SRWieZ "SRWieZ (8 commits)")[![twmobius](https://avatars.githubusercontent.com/u/854155?v=4)](https://github.com/twmobius "twmobius (6 commits)")[![stanma](https://avatars.githubusercontent.com/u/1821782?v=4)](https://github.com/stanma "stanma (5 commits)")[![commanddotcom](https://avatars.githubusercontent.com/u/735385?v=4)](https://github.com/commanddotcom "commanddotcom (4 commits)")[![JellyBellyDev](https://avatars.githubusercontent.com/u/190820?v=4)](https://github.com/JellyBellyDev "JellyBellyDev (4 commits)")[![dizzy7](https://avatars.githubusercontent.com/u/1052472?v=4)](https://github.com/dizzy7 "dizzy7 (3 commits)")[![sharevb](https://avatars.githubusercontent.com/u/29117330?v=4)](https://github.com/sharevb "sharevb (3 commits)")[![underdpt](https://avatars.githubusercontent.com/u/8122137?v=4)](https://github.com/underdpt "underdpt (2 commits)")[![aragon999](https://avatars.githubusercontent.com/u/6317761?v=4)](https://github.com/aragon999 "aragon999 (2 commits)")[![ebrana-devs](https://avatars.githubusercontent.com/u/7850167?v=4)](https://github.com/ebrana-devs "ebrana-devs (2 commits)")[![fmayorov](https://avatars.githubusercontent.com/u/120632579?v=4)](https://github.com/fmayorov "fmayorov (2 commits)")[![georaldc](https://avatars.githubusercontent.com/u/286812?v=4)](https://github.com/georaldc "georaldc (2 commits)")[![hyncica](https://avatars.githubusercontent.com/u/11272692?v=4)](https://github.com/hyncica "hyncica (2 commits)")[![janbarasek](https://avatars.githubusercontent.com/u/4738758?v=4)](https://github.com/janbarasek "janbarasek (2 commits)")

### Embed Badge

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

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

PHPackages © 2026

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