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

ActivePhp-class[Mail &amp; Notifications](/categories/mail)

israelfl/imap-client
====================

Simple but powerful Imap client.

0.0.10(7y ago)0681MITPHPPHP &gt;=5.3

Since Jan 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/israelfl/imap-client)[ Packagist](https://packagist.org/packages/israelfl/imap-client)[ RSS](/packages/israelfl-imap-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)DependenciesVersions (11)Used By (0)

PHP Imap Client
===============

[](#php-imap-client)

Copyright (c) 2016 Tobias Zeising,

Licensed under the MIT license

Features
--------

[](#features)

This PHP IMAP Client is a simple class for IMAP Email access. It base on the [PHP IMAP extension](http://at1.php.net/imap) and offers a simple interface for handling emails. In my opinion the PHP IMAP functions are not very intuitive.

- simple interface
- get emails and folders
- move, delete, count emails
- rename, delete and add folders
- get attachments

How to use
----------

[](#how-to-use)

Instantiating the class will open the imap connection.

```
$mailbox = 'my.imapserver.com';
$username = 'myuser';
$password = 'secret';
$encryption = 'tls'; // or ssl or '';
$imap = new Imap($mailbox, $username, $password, $encryption);

if($imap->isConnected()===false) {
    die($imap->getError());
}
```

Now you can fetch all available folders:

```
$folders = $imap->getFolders(); // returns array of strings
foreach($folders as $folder) {
    echo $folder;
}
```

Now you can select a folder:

```
$imap->selectFolder("Inbox");
```

Once you selected a folder you can count the messages in this folder:

```
$overallMessages = $imap->countMessages();
$unreadMessages = $imap->countUnreadMessages();
```

Okay, now lets fetch all emails in the currently selected folder (in our example the "Inbox"):

```
$emails = $imap->getMessages();
var_dump($emails);
```

getMessages() will not mark emails as read! It will return the following structure without changing the emails. In this example two emails are in the Inbox.

```
array(2) {
  [0]=>
  array(8) {
    ["to"]=>
    array(1) {
      [0]=>
      string(30) "Tobias Zeising "
    }
    ["from"]=>
    string(30) "Karl Mustermann "
    ["date"]=>
    string(31) "Fri, 27 Dec 2013 18:44:52 +0100"
    ["subject"]=>
    string(12) "Test Subject"
    ["id"]=>
    int(15)
    ["unread"]=>
    bool(true)
    ["answered"]=>
    bool(false)
    ["body"]=>
    string(240) "This is a test body.

    With a bit html.

    and without attachment
    "
  }
  [1]=>
  array(9) {
    ["to"]=>
    array(1) {
      [0]=>
      string(29) "tobias.zeising@aditu.de "
    }
    ["from"]=>
    string(40) "Karl Ruediger "
    ["date"]=>
    string(31) "Thu, 19 Dec 2013 17:45:37 +0100"
    ["subject"]=>
    string(19) "Test mit Attachment"
    ["id"]=>
    int(14)
    ["unread"]=>
    bool(false)
    ["answered"]=>
    bool(false)
    ["body"]=>
    string(18) "Anbei eine Datei"
    ["attachments"]=>
    array(1) {
      [0]=>
      array(2) {
        ["name"]=>
        string(24) "640 x 960 (iPhone 4).jpg"
        ["size"]=>
        int(571284)
      }
    }
  }
}
```

You can also add/rename/delete folders. Lets add a new folder:

```
$imap->addFolder('archive');
```

Now we move the first email into this folder

```
$imap->moveMessage($emails[0]['id'], 'archive');
```

And we delete the second email from inbox

```
$imap->deleteMessage($emails[1]['id']);
```

Methods
-------

[](#methods)

Following methods are available.

- `__construct($mailbox, $username, $password, $encryption)` open new imap connection
- `isConnected()` check whether the imap connection could be opened successfully
- `getError()` returns the last error message
- `selectFolder($folder)` select current folder
- `getFolders()` get all available folders
- `setEmbed($val)` If true, embed all 'inline' images into body HTML, accesible in 'body\_embed'
- `countMessages()` count messages in current folder
- `countUnreadMessages()` count unread messages in current folder
- `getMessages($withbody = true)` get emails in current folder
- `getMessage($id, $withbody = true)` get email by given id
- `deleteMessage($id)` delete message with given id
- `deleteMessages($ids)` delete messages with given ids (as array)
- `moveMessage($id, $target)` move message with given id in new folder
- `moveMessages($ids, $target)` move messages with given ids (as array) in new folder
- `setUnseenMessage($id, $seen = true)` set unseen state of the message with given id
- `getAttachment($id, $index = 0)` get attachment of the message with given id (getMessages returns all available attachments)
- `addFolder($name)` add new folder with given name
- `removeFolder($name)` delete folder with fiven name
- `renameFolder($name, $newname)` rename folder with given name
- `purge()` move all emails in the current folder into trash. emails in trash and spam will be deleted
- `getAllEmailAddresses()` returns all email addresses of all emails (for auto suggestion list)
- `saveMessageInSent($header, $body)` save a sent message in sent folder
- `getMailboxStatistics()` returns statistics, see [imap\_mailboxmsginfo](http://php.net/manual/de/function.imap-mailboxmsginfo.php)

Feedback
--------

[](#feedback)

Feel free to improve this class. You can use the pull request function of github for contributing improvments. The inner structure of this class is simple and easy. Don't hesitate and check it out ;)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 59.2% 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 ~45 days

Recently: every ~99 days

Total

10

Last Release

2623d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/803bbb75244961665da9da7cc1eb8a8b929c8c293bd9153798c2be118104bb84?d=identicon)[israelfl](/maintainers/israelfl)

---

Top Contributors

[![SSilence](https://avatars.githubusercontent.com/u/678855?v=4)](https://github.com/SSilence "SSilence (42 commits)")[![natanfelles](https://avatars.githubusercontent.com/u/3011423?v=4)](https://github.com/natanfelles "natanfelles (6 commits)")[![developarts](https://avatars.githubusercontent.com/u/3060193?v=4)](https://github.com/developarts "developarts (6 commits)")[![MikeWillis](https://avatars.githubusercontent.com/u/1608860?v=4)](https://github.com/MikeWillis "MikeWillis (3 commits)")[![dutchakdev](https://avatars.githubusercontent.com/u/1294321?v=4)](https://github.com/dutchakdev "dutchakdev (3 commits)")[![henriquesalvan](https://avatars.githubusercontent.com/u/6931387?v=4)](https://github.com/henriquesalvan "henriquesalvan (2 commits)")[![melcak](https://avatars.githubusercontent.com/u/18522?v=4)](https://github.com/melcak "melcak (2 commits)")[![teson2000](https://avatars.githubusercontent.com/u/1379148?v=4)](https://github.com/teson2000 "teson2000 (1 commits)")[![artemiusgreat](https://avatars.githubusercontent.com/u/5140879?v=4)](https://github.com/artemiusgreat "artemiusgreat (1 commits)")[![fulldecent](https://avatars.githubusercontent.com/u/382183?v=4)](https://github.com/fulldecent "fulldecent (1 commits)")[![parturi](https://avatars.githubusercontent.com/u/5240702?v=4)](https://github.com/parturi "parturi (1 commits)")[![radub](https://avatars.githubusercontent.com/u/60108?v=4)](https://github.com/radub "radub (1 commits)")[![russ-ab](https://avatars.githubusercontent.com/u/6732815?v=4)](https://github.com/russ-ab "russ-ab (1 commits)")[![andryyy](https://avatars.githubusercontent.com/u/2972950?v=4)](https://github.com/andryyy "andryyy (1 commits)")

---

Tags

phpmailclassimap

### Embed Badge

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

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

###  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)[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)[benhall14/php-imap-reader

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

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

PHPackages © 2026

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