PHPackages                             bapcltd/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. [Mail &amp; Notifications](/categories/mail)
4. /
5. bapcltd/php-imap

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

bapcltd/php-imap
================

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

v0.6.1(6y ago)015[2 issues](https://github.com/bapcltd/php-imap/issues)MITPHPPHP ^7.4

Since Jan 20Pushed 4y agoCompare

[ Source](https://github.com/bapcltd/php-imap)[ Packagist](https://packagist.org/packages/bapcltd/php-imap)[ Docs](https://github.com/bapcltd-marv/php-imap)[ RSS](/packages/bapcltd-php-imap/feed)WikiDiscussions main Synced 4w ago

READMEChangelogDependencies (12)Versions (18)Used By (0)

PHP IMAP
========

[](#php-imap)

[![Release](https://camo.githubusercontent.com/b0cde6c3c8f410681f34512a8385c87a7cdd58d1a029ef156514840d0a63ee06/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626170636c74642f7068702d696d61702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bapcltd/php-imap)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Packagist](https://camo.githubusercontent.com/fde1971508300440f2638d8cdc2d9c12f795b009c575ecd52aace27226f4da8e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626170636c74642f7068702d696d61702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bapcltd/php-imap)[![Build Status](https://camo.githubusercontent.com/44077a8a13e25712ae43f57d06eec9f3b779b1284a9457e9e9cc853c4b5d253b/68747470733a2f2f7472617669732d63692e6f72672f626170636c74642f7068702d696d61702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/bapcltd/php-imap)[![Supported PHP Version](https://camo.githubusercontent.com/fdb2f6287ce24ec4238a075ecb3d99586c59df237bd45d2610541793fe2fbe01/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7068702d762f626170636c74642f7068702d696d61702e737667)](README.md)[![Maintainability](https://camo.githubusercontent.com/b3aa460017bbcac74adb08ef8d3ac5038f818d63883d7b35f1e32b6583881827/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f31613364313836333335393763653563386538392f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/bapcltd/php-imap/maintainability)[![Test Coverage](https://camo.githubusercontent.com/c18feb97055b1e433c0bf69570cae055df56c7ce73d9598181811f336be25e53/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f626170636c74642f7068702d696d61702f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/bapcltd/php-imap?branch=master)[![Type Coverage](https://camo.githubusercontent.com/a561fbd389b5d17c3c1cc2942524b880066efd035b824b5706e87e4d4ee1eb6b/68747470733a2f2f73686570686572642e6465762f6769746875622f626170636c74642f7068702d696d61702f636f7665726167652e737667)](https://shepherd.dev/github/bapcltd/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.

Forked in 2020, [see original](https://github.com/barbushin/php-imap).

### 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 7.4
- 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`

### Installation by Composer

[](#installation-by-composer)

Install the latest available and may unstable source code from `master`, which is may not properly tested yet:

```
$ composer require bapcltd/php-imap:dev-master

```

### Run Tests

[](#run-tests)

Before you can run the 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 of 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 of the installed `php-imap` directory): `php vendor/bin/phpunit --testdox`

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

```
// 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)
);

// 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: http://php.net/manual/en/function.imap-search.php
	$mailsIds = $mailbox->searchMailbox('ALL');
} catch(PhpImap\Exceptions\ConnectionException $ex) {
	echo "IMAP connection failed: " . $ex;
	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 attachements of $mail
echo "\n\nAttachments:\n";
print_r($mail->getAttachments());
```

Method imap() allows to call any imap function in a context of the the instance:

```
// Call imap_check();
// http://php.net/manual/en/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 mailboxs
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);
```

### Recommended

[](#recommended)

- [Original Release](https://github.com/barbushin/php-imap)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 63.4% 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 ~31 days

Recently: every ~60 days

Total

9

Last Release

2053d ago

Major Versions

v0.6.1 → 3.x-dev2020-09-23

PHP version history (2 changes)v0.1.0PHP ^7.4

3.x-devPHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/4937b5a36d5dddd23dc3cca53252d5b218ca8b57d4b431b40c472076a631a12c?d=identicon)[bapcltd-marv](/maintainers/bapcltd-marv)

---

Top Contributors

[![bapcltd-marv](https://avatars.githubusercontent.com/u/46891309?v=4)](https://github.com/bapcltd-marv "bapcltd-marv (659 commits)")[![barbushin](https://avatars.githubusercontent.com/u/683352?v=4)](https://github.com/barbushin "barbushin (148 commits)")[![Sebbo94BY](https://avatars.githubusercontent.com/u/5154682?v=4)](https://github.com/Sebbo94BY "Sebbo94BY (148 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 (9 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)")[![agrisvv](https://avatars.githubusercontent.com/u/8926651?v=4)](https://github.com/agrisvv "agrisvv (2 commits)")[![alejobit](https://avatars.githubusercontent.com/u/12930197?v=4)](https://github.com/alejobit "alejobit (2 commits)")[![ebrana-devs](https://avatars.githubusercontent.com/u/7850167?v=4)](https://github.com/ebrana-devs "ebrana-devs (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)")[![Jekis](https://avatars.githubusercontent.com/u/1102024?v=4)](https://github.com/Jekis "Jekis (2 commits)")[![jlsalvador](https://avatars.githubusercontent.com/u/1464850?v=4)](https://github.com/jlsalvador "jlsalvador (2 commits)")[![nickl-](https://avatars.githubusercontent.com/u/1404606?v=4)](https://github.com/nickl- "nickl- (2 commits)")

---

Tags

phpmailimappop3mailboxreceive emails

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[php-imap/php-imap

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

1.7k12.9M42](/packages/php-imap-php-imap)[webklex/php-imap

PHP IMAP client

4365.5M14](/packages/webklex-php-imap)[benhall14/php-imap-reader

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

3516.6k](/packages/benhall14-php-imap-reader)[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)

PHPackages © 2026

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