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

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

sazanof/php-imap-sockets
========================

PHP IMAP Library, based on sockets

1.1.2(2y ago)148MITPHP

Since Aug 4Pushed 2y ago1 watchersCompare

[ Source](https://github.com/sazanof/php-imap-sockets)[ Packagist](https://packagist.org/packages/sazanof/php-imap-sockets)[ RSS](/packages/sazanof-php-imap-sockets/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

[![Logo](https://raw.githubusercontent.com/sazanof/php-imap-sockets/main/files/logo.png)](https://raw.githubusercontent.com/sazanof/php-imap-sockets/main/files/logo.png)

PHP IMAP SOCKETS
================

[](#php-imap-sockets)

**NEW library for working with email, using sockets.**

Features
--------

[](#features)

- Dependency free
- Body structure analyze via \[BODYSTRUCTURE\] command
- Flexible search and fetch
- Attachments support (inline too)
- Flags management
- Pagination

### Todo

[](#todo)

- Sorting

Install via composer
--------------------

[](#install-via-composer)

To install this project run

```
  composer require sazanof/php-imap-sockets
```

Website (comming soon)
----------------------

[](#website-comming-soon)

[Documentation](https://sazanof.ru)

Basic usage
-----------

[](#basic-usage)

### Connection

[](#connection)

```
use \Sazanof\PhpImapSockets\Models\Connection;

// create new connection
$connection = new Connection('imap.example.com');
// open connection and enable debug
$connection->open()->enableDebug();
// login
$connection->login('USERNAME', 'PASSWORD');
```

### Query

[](#query)

```
use \Sazanof\PhpImapSockets\Models\SearchQuery;

$query = new SearchQuery();
$query->all();
// OR
$query->subject('Test');
// OR
$query->new();
// OR
$query->or([
	'subject'=>[
		'One',
		'Two'
	],
	'since'=>'01-Jan-2023'
]);
// Use clear() method to clear query string
$query->clear();
```

### Mailbox

[](#mailbox)

```
$path = 'INBOX';
$mailbox = $connection->getMailboxByPath($path)->setConnection($connection)->select();
// array of messages NUMBERS (not UIDS)
$uids = $mailbox->search($query)->msgNums();
// or
$mailbox->search($query)->setOrderDirection('DESC')->msgNums() // or ASC
```

### Messages

[](#messages)

```
use \Sazanof\PhpImapSockets\Models\MessageCollection;

$collection = new MessageCollection($uids, $mailbox);
// array of "Message"
$items = $collection->items();
```

### Pagination

[](#pagination)

```
use \Sazanof\PhpImapSockets\Models\Paginator;

$paginator = new \Sazanof\PhpImapSockets\Models\Paginator($uids, $mailbox, 1, 6);
$messagesPaginated = $p->messages();
```

### Attachments

[](#attachments)

```
/** @var \Sazanof\PhpImapSockets\Models\Message $message **/
$attachmentsParts = $message->getBodyStructure()->getAttachmentParts();
foreach ($attachmentsParts as $attachmentsPart) {
    if (!$attachmentsPart->isInline()) {
        // set attachment content to $attachmentsPart
        $attachmentsPart->setContent(
            $message->getAttachment($attachmentsPart->getSection()) // or save locally
        );
    }
}
```

### Text content of message

[](#text-content-of-message)

```
/** @var \Sazanof\PhpImapSockets\Models\Message $message **/
//get text parts (plain,html) with inline images
$message->getBodyStructure()->getTextParts();
```

### Flags management

[](#flags-management)

```
use \Sazanof\PhpImapSockets\Models\Message;

//$message
$message->setImportant()->markAsDeleted();
//or
$message->addFlags(['one','two'])
//or
$message->replaceFlags(['one','two'])
//or
$message->clearFlags()
//or
$message->deleteFlags('one');
//trigger save
$message->saveFlags();
```

Authors
-------

[](#authors)

- [@sazanof](https://www.github.com/sazanof)

License
-------

[](#license)

[MIT](https://choosealicense.com/licenses/mit/)

Feedback
--------

[](#feedback)

If you detected any security issues, please reach out to us at

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

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 ~4 days

Total

4

Last Release

1052d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/349fe72695f607c07d696dca00987ec1ce529b190912bead455b0d717caab636?d=identicon)[sazanof](/maintainers/sazanof)

---

Tags

emailemailsimaplibraryphp-imapphp-imap-clientsockets

### Embed Badge

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

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

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M343](/packages/drupal-core-dev)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M421](/packages/drupal-core-recommended)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)

PHPackages © 2026

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