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

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

dg/imap
=======

Retrieval, processing, and manipulation of emails within a mailbox via POP3, IMAP and NNTP

v1.0.0(2y ago)729BSD-3-ClausePHPPHP &gt;=8.1CI passing

Since Nov 29Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/dg/imap)[ Packagist](https://packagist.org/packages/dg/imap)[ RSS](/packages/dg-imap/feed)WikiDiscussions master Synced yesterday

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

IMAP Library for PHP
====================

[](#imap-library-for-php)

[![Downloads this Month](https://camo.githubusercontent.com/13b110cefab734c6eabb8d9c9d2b8187de6d22e24258014100da052a89569bf7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f64672f696d61702e737667)](https://packagist.org/packages/dg/imap)[![Tests](https://github.com/dg/imap/workflows/Tests/badge.svg?branch=master)](https://github.com/dg/imap/actions)[![Latest Stable Version](https://camo.githubusercontent.com/9864e0486ed2d2efc37f56a9fd750d7bd2b861888abbc055f5d354e4267d82d9/68747470733a2f2f706f7365722e707567782e6f72672f64672f696d61702f762f737461626c65)](https://github.com/dg/imap/releases)[![License](https://camo.githubusercontent.com/fa7d5fcf2c84b580327af52da95dd751703af65f079dc3c5a0081beac0789718/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4e65772532304253442d626c75652e737667)](https://github.com/dg/imap/blob/master/license.md)

This IMAP Library for PHP provides an intuitive and easy-to-use interface to interact with POP3, IMAP and NNTP mail servers. It allows for operations such as connecting to mailboxes, fetching messages, handling message parts, and managing email content.

- Connect to IMAP servers with ease
- Fetch and manage email messages
- Handle different parts of an email such as attachments and text
- Decode email content and headers
- Supports message deletion and structure analysis

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

[](#installation)

To install the library, you can use Composer. Run the following command in your project directory:

```
composer require dg/imap
```

It requires PHP version 8.1 with extension imap.

Connecting to a Mailbox
-----------------------

[](#connecting-to-a-mailbox)

To connect to an IMAP mailbox, create an instance of the `Mailbox` class.

```
use DG\Imap\Mailbox;

$mailbox = new Mailbox(
	'{imap.gmail.com:993/imap/ssl}',
	'your_username@gmai.com',
	'your_password',
);

$mailbox->connect();
```

Fetching Messages
-----------------

[](#fetching-messages)

Fetch all messages from the mailbox:

```
$messages = $mailbox->getMessages();
foreach ($messages as $message) {
	echo $message->getSubject() . "\n";
}
```

Handling Message Parts
----------------------

[](#handling-message-parts)

To handle different parts of a message, such as attachments:

```
foreach ($messages as $message) {
	$parts = $message->getParts();
	foreach ($parts as $part) {
		// Process each part
	}
}
```

Certainly, here's the additional information regarding error handling through exceptions:

Error Handling
--------------

[](#error-handling)

In case of any issue, such as a failure to connect to the IMAP server, fetch messages, or process message parts, the library will throw an `DG\Imap\Exception`:

```
try {
    $mailbox->connect();
    $messages = $mailbox->getMessages();
    // ... additional operations
} catch (DG\Imap\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}
```

Support Project
---------------

[](#support-project)

Do you like this project?

[![Donate](https://camo.githubusercontent.com/2dd1529e9dabe93bc54843d8f07c6089790b57f1357f23af1c108fb09f3c1de0/68747470733a2f2f66696c65732e6e657474652e6f72672f69636f6e732f646f6e6174696f6e2d312e7376673f)](https://nette.org/make-donation?to=imap)

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance52

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

947d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/17f266513a3ca97500ec3d85d562b9279c7a6346358fe2b8d90390ece717a027?d=identicon)[david@grudl.com](/maintainers/david@grudl.com)

---

Top Contributors

[![dg](https://avatars.githubusercontent.com/u/194960?v=4)](https://github.com/dg "dg (7 commits)")

---

Tags

imap-clientnntp-clientpop3-clientmailimappop3

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[php-imap/php-imap

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

1.7k13.4M52](/packages/php-imap-php-imap)[webklex/php-imap

PHP IMAP client

4466.7M27](/packages/webklex-php-imap)[ddeboer/imap

Object-oriented IMAP for PHP

9364.1M15](/packages/ddeboer-imap)[tedivm/fetch

A PHP IMAP Library

5171.2M8](/packages/tedivm-fetch)[directorytree/imapengine

A fully-featured IMAP library -- without the PHP extension

551284.6k9](/packages/directorytree-imapengine)[benhall14/php-imap-reader

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

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

PHPackages © 2026

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