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

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

port-adhoc/imap
===============

Imap class for PHP

v0.1.31(8y ago)152MITPHPPHP &gt;=5.3.0

Since Nov 20Pushed 8y ago1 watchersCompare

[ Source](https://github.com/port-adhoc/imap-php)[ Packagist](https://packagist.org/packages/port-adhoc/imap)[ RSS](/packages/port-adhoc-imap/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (33)Used By (0)

[![Packagist minimum PHP version](https://camo.githubusercontent.com/c5caa75aa8ddc1f3fee3e6068548e213e15507cfcb2d68267e03615f236289f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706f72742d6164686f632f696d61702e737667)](https://camo.githubusercontent.com/c5caa75aa8ddc1f3fee3e6068548e213e15507cfcb2d68267e03615f236289f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f706f72742d6164686f632f696d61702e737667)[![Packagist version](https://camo.githubusercontent.com/08dc5655cdf7d846dff96424eb5f046800ef8b9db9ef064caeeafdab5e54a909/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706f72742d6164686f632f696d61702e737667)](https://camo.githubusercontent.com/08dc5655cdf7d846dff96424eb5f046800ef8b9db9ef064caeeafdab5e54a909/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706f72742d6164686f632f696d61702e737667)[![Packagist licence](https://camo.githubusercontent.com/536538bd631e0d3be561953ff3c49440f8c06df78c6ab7c991cc0cfb44ad771d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706f72742d6164686f632f696d61702e737667)](https://camo.githubusercontent.com/536538bd631e0d3be561953ff3c49440f8c06df78c6ab7c991cc0cfb44ad771d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706f72742d6164686f632f696d61702e737667)

imap-php
========

[](#imap-php)

Uid oriented Imap class

Summary
=======

[](#summary)

- [Installation](#installation)
- [Usage](#usage)
- [Function list](#function-list)

Installation
============

[](#installation)

In your repository :

```
composer require port-adhoc/imap
```

[back to summary](#summary)

Usage
=====

[](#usage)

- [Example 1 : traversing a whole mailbox and retriving its content](#example-1--traversing-a-whole-mailbox-and-retriving-its-content)

Example 1 : traversing a whole mailbox and retriving its content
----------------------------------------------------------------

[](#example-1--traversing-a-whole-mailbox-and-retriving-its-content)

```
use PortAdhoc\Imap\Imap;
use PortAdhoc\Imap\Encoding;

$imap = new Imap;

$imap->server = 'example.host.com';
$imap->port = 993;
$imap->flags = ['imap', 'ssl', 'readonly'];
$imap->user = 'example@host.com';
$imap->password = 'example';
$imap->mailbox = 'INBOX';
$imap->start = '1';
$imap->end = '*';

$imap->connect();

$messages = $imap->getMessages();

foreach( $messages as $message ) {
  $subject = $message->getSubject();
  $date = $message->getDate();
  $from = $message->getFrom();
  $to = $message->getTo();
  $cc = $message->getCC();
  $bcc = $message->getBCC();
  $text = $message->getPlainText( Encoding::UTF_8 );
  $html = $message->getPlainText( Encoding::UTF_8 );
  $attachments = $message->getAttachments();
}
```

[back to summary](#summary)

Function list
=============

[](#function-list)

- [`Attachment::`](#attachment)
    - [`getName`](#getname)
    - [`getContent`](#getcontent)
- [`Email::`](#email)
    - [`properties`](#email-properties)
        - [`name`](#email-property-name)
        - [`email`](#email-property-email)
- [`Imap::`](#imap)
    - [`construct`](#imap-construct)
    - [`properties`](#imap-properties)
        - [`server`](#imap-property-server)
        - [`port`](#imap-property-port)
        - [`flags`](#imap-property-flags)
        - [`user`](#imap-property-user)
        - [`password`](#imap-property-password)
        - [`mailbox`](#imap-property-mailbox)
        - [`start`](#imap-property-start)
        - [`end`](#imap-property-end)
        - [`connection_time`](#imap-property-connection_time)
        - [`message_fetching_time`](#imap-property-message_fetching_time)
    - [`connect`](#connect)
    - [`getConnectionString`](#getconnectionstring)
    - [`getMessage`](#getmessage)
    - [`getMessages`](#getmessages)
- [`Message::`](#message)
    - [`getAttachments`](#getattachments)
    - [`getBCC`](#getbcc)
    - [`getCC`](#getcc)
    - [`getDate`](#getdate)
    - [`getFrom`](#getfrom)
    - [`getHtml`](#gethtml)
    - [`getImap`](#getimap)
    - [`getInReplyTo`](#getinreplyto)
    - [`getMessageId`](#getmessageid)
    - [`getMsgno`](#getmsgno)
    - [`getPlainText`](#getplaintext)
    - [`getReferences`](#getreferences)
    - [`getReplyTo`](#getreplyto)
    - [`getReturnPath`](#getreturnpath)
    - [`getSender`](#getsender)
    - [`getStructure`](#getstructure)
    - [`getSubject`](#getsubject)
    - [`getTo`](#getto)
    - [`getUid`](#getuid)
    - [`isAnswered`](#isAnswered)
    - [`isDeleted`](#isdeleted)
    - [`isDraft`](#isdraft)

Attachment
----------

[](#attachment)

### getName

[](#getname)

```
public function getName(): string
```

Example:

```
use PortAdhoc\Imap\Imap;

$imap = new Imap;

$imap->server = 'example.host.com';
$imap->port = 993;
$imap->flags = ['imap', 'ssl', 'readonly'];
$imap->user = 'example@host.com';
$imap->password = 'example';
$imap->mailbox = 'INBOX'; // or INBOX/folder
$imap->start = '500'; // uid
$imap->end = '500'; // uid

$imap->connect();

$uid = 500;

$message = $imap->getMessage( $uid );

$attachments = $message->getAttachments();

foreach( $attachments as $attachment ) {
	$name = $attachment->getName();

	echo $name;
}
```

Result:

```
> php script.php
reporting result quarter 4.xlsx
```

### getContent

[](#getcontent)

```
public function getContent(): string
```

Example:

```
use PortAdhoc\Imap\Imap;

$imap = new Imap;

$imap->server = 'example.host.com';
$imap->port = 993;
$imap->flags = ['imap', 'ssl', 'readonly'];
$imap->user = 'example@host.com';
$imap->password = 'example';
$imap->mailbox = 'INBOX'; // or INBOX/folder
$imap->start = '500'; // uid
$imap->end = '500'; // uid

$imap->connect();

$uid = 500;

$message = $imap->getMessage( $uid );

$attachments = $message->getAttachments();

foreach( $attachments as $attachment ) {
	$name = $attachment->getName();
	$content = $attachement->getContent();
	$path = __DIR__ . '/' . $name; // inside the current repository

	file_put_contents( $path, $content );
}
```

Result:

```
/vendor
composer.json
composer.lock
script.php
reporting result quarter 4.xlsx
```

Imap
----

[](#imap)

### Imap construct

[](#imap-construct)

```
public function __construct(): PortAdhoc\Imap\Imap
```

Example:

```
use PortAdhoc\Imap\Imap;

$imap = new Imap;
```

[back to function list](#function-list)

[back to summary](#summary)

### Imap properties

[](#imap-properties)

```
public string $server;
public int $port;
public string $user;
public string $password;
public string $mailbox;
public int $connection_time;
public int $message_fetching_time;
public string $start; // uid
public string $end; // uid
```

[back to function list](#function-list)

[back to summary](#summary)

### connect

[](#connect)

```
public function connect(): PortAdhoc\Imap\Imap
```

Example:

```
use PortAdhoc\Imap\Imap;

$imap = new Imap;

$imap->server = 'example.host.com';
$imap->port = 993;
$imap->flags = ['imap', 'ssl', 'readonly'];
$imap->user = 'example@host.com';
$imap->password = 'example';
$imap->mailbox = 'INBOX'; // or INBOX/folder
$imap->start = '1'; // uid
$imap->end = '500'; // uid

$imap->connect();
```

[back to function list](#function-list)

[back to summary](#summary)

### getMessage

[](#getmessage)

```
public function getMessage( int $uid ): PortAdhoc\Imap\Message
```

Example:

```
use PortAdhoc\Imap\Imap;

$imap = new Imap;

$imap->server = 'example.host.com';
$imap->port = 993;
$imap->flags = ['imap', 'ssl', 'readonly'];
$imap->user = 'example@host.com';
$imap->password = 'example';
$imap->mailbox = 'INBOX'; // or INBOX/folder
$imap->start = '1'; // uid
$imap->end = '500'; // uid

$imap->connect();

$uid = 500;

$message = $imap->getMessage( $uid );
```

[back to function list](#function-list)

[back to summary](#summary)

### getMessages

[](#getmessages)

```
public function getMessages(): PortAdhoc\Imap\Message[]
```

Example:

```
use PortAdhoc\Imap\Imap;

$imap = new Imap;

$imap->server = 'example.host.com';
$imap->port = 993;
$imap->flags = ['imap', 'ssl', 'readonly'];
$imap->user = 'example@host.com';
$imap->password = 'example';
$imap->mailbox = 'INBOX'; // or INBOX/folder
$imap->start = '1'; // uid
$imap->end = '500'; // uid

$imap->connect();

$messages = $imap->getMessages();

foreach( $messages as $message ) {
  // ...
}
```

[back to function list](#function-list)

[back to summary](#summary)

### getConnectionString

[](#getconnectionstring)

```
public function getConnectionString(): string
```

Example:

```
use PortAdhoc\Imap\Imap;

$imap = new Imap;

$imap->server = 'example.host.com';
$imap->port = 993;
$imap->flags = ['imap', 'ssl', 'readonly'];
$imap->user = 'example@host.com';
$imap->password = 'example';
$imap->mailbox = 'INBOX'; // or INBOX/folder
$imap->start = '1'; // uid
$imap->end = '500'; // uid

$cs = $imap->getConnectionString();

echo $cs;
```

Result:

```
> php script.php
{example.host.com:993/imap/ssl/readonly}INBOX/folder
```

[back to function list](#function-list)

[back to summary](#summary)

Email
-----

[](#email)

### Email properties

[](#email-properties)

```
public $email;
public $name;
```

Example:

```
use PortAdhoc\Imap\Imap;

$imap = new Imap;

$imap->server = 'example.host.com';
$imap->port = 993;
$imap->flags = ['imap', 'ssl', 'readonly'];
$imap->user = 'example@host.com';
$imap->password = 'example';
$imap->mailbox = 'INBOX';

$uid = 500;

$message = $imap->getMessage( $uid );

$from = $message->getFrom();

$email = $from->email;
$name = $from->name;

echo $name . ' ' . $email;
```

Result:

```
> php script.php
John Doe john.doe@contoso.com
```

[back to function list](#function-list)

[back to summary](#summary)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Every ~0 days

Total

32

Last Release

3081d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15908747?v=4)[Anwar](/maintainers/khalyomede)[@khalyomede](https://github.com/khalyomede)

---

Top Contributors

[![khalyomede](https://avatars.githubusercontent.com/u/15908747?v=4)](https://github.com/khalyomede "khalyomede (51 commits)")

---

Tags

attachmentsemailhtmlimapimap-phpmessageplain-textuid

### Embed Badge

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

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

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M228](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M52](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

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