PHPackages                             vasim-seta/codeigniter-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. vasim-seta/codeigniter-imap

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

vasim-seta/codeigniter-imap
===========================

CodeIgniter IMAP client

0.1.2(4y ago)32851[1 issues](https://github.com/vasim-seta/codeigniter-imap/issues)MITPHPPHP &gt;=5.5.9

Since Jun 14Pushed 3y ago2 watchersCompare

[ Source](https://github.com/vasim-seta/codeigniter-imap)[ Packagist](https://packagist.org/packages/vasim-seta/codeigniter-imap)[ Docs](https://github.com/vasim/codeigniter-imap)[ RSS](/packages/vasim-seta-codeigniter-imap/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (3)DependenciesVersions (4)Used By (0)

IMAP Library for CodeIgniter
============================

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

\[!\[Latest Version on Packagist\]\[ico-version\]\]\[link-packagist\] [!\[Software License\]\[ico-license\]](LICENSE.md)\[!\[Build Status\]\[ico-travis\]\]\[link-travis\] \[!\[Total Downloads\]\[ico-downloads\]\]\[link-downloads\]

Description
-----------

[](#description)

CodeIgniter IMAP is an easy way to integrate the native php imap library into your **CodeIgniter** app.

Note: this library is forked from webklex/laravel-imap which was imap library for laravel, but i need to use it in CodeIgniter and without few changes in the library i can't use it in CodeIgniter. So, I have copied it and changed it as needed. but then i got idea to publish it because there maybe lots of people who wants to use that laravel library in CodeIgniter without doing any changes. Also i have changed things which i have used and needed, there might be issue or error in other things, there will be few trash files and methods of/for laravel as well. If you got any issue then please feel free to report that or you can fork this and do it your self. I have also tried to use webklex/php-imap but i was unable to use it because of few errors and i didn't have much time to figure that out. I have never created any library and i don't know about licencing much more, so please let me know if any issue regarding licencing or anything else then i will remove it from here.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Documentation](#documentation)
    - [Client::class](#clientclass)
    - [Message::class](#messageclass)
    - [Folder::class](#folderclass)
    - [Attachment::class](#attachmentclass)
    - [MessageCollection::class](#messagecollectionclass)
    - [AttachmentCollection::class](#attachmentcollectionclass)
    - [FolderCollection::class](#foldercollectionclass)
- [Known issues](#known-issues)
- [Milestones &amp; upcoming features](#milestones--upcoming-features)
- [Security](#security)
- [Credits](#credits)
- [Supporters](#supporters)
- [License](#license)

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

[](#installation)

1. Install the php-imap library if it isn't already installed:

```
sudo apt-get install php*-imap && sudo apache2ctl graceful
```

You might also want to check `phpinfo()` if the extension is enabled.

2. Now install the CodeIgniter IMAP package by running the following command:

```
composer require vasim-seta/codeigniter-imap
```

Configuration
-------------

[](#configuration)

when there is no setting define while calling IMAP/Client then it will use these default settings, you might want to add the following to your `application/config/config.php` file.

```
$config['imap']['host']             = 'localhost';
$config['imap']['port']             = 993;
$config['imap']['encryption']       = 'ssl';
$config['imap']['validate_cert']    = TRUE;
$config['imap']['username']         = 'root@example.com';
$config['imap']['password']         = '';

$config['imap.options.open']        = [];
$config['imap.options.delimiter']   = '/';

```

The following encryption methods are supported:

- `false` — Disable encryption
- `ssl` — Use SSL
- `tls` — Use TLS

Detailed \[application/config/config.php\] configuration:

- `host` — imap host
- `port` — imap port
- `encryption` — desired encryption method
- `validate_cert` — decide weather you want to verify the certificate or not
- `username` — imap account username
- `password` — imap account password
- `imap.options` — additional fetch options
    - `delimiter` — you can use any supported char such as ".", "/", etc
    - `fetch` — `FT_UID` (message marked as read by fetching the message) or `FT_PEEK` (fetch the message without setting the "read" flag)
    - `fetch_body` — If set to `false` all messages will be fetched without the body and any potential attachments
    - `fetch_attachment` — If set to `false` all messages will be fetched without any attachments
    - `open` — special configuration for imap\_open()
        - `DISABLE_AUTHENTICATOR` — Disable authentication properties.

Usage
-----

[](#usage)

This is a basic example, which will echo out all Mails within all imap folders and will move every message into INBOX.read. Please be aware that this should not ben tested in real live but it gives an impression on how things work.

```
$oClient = new \Vasim\IMAP\Client([
    'host'          => 'somehost.com',
    'port'          => 993,
    'encryption'    => 'ssl',
    'validate_cert' => true,
    'username'      => 'username',
    'password'      => 'password',
]);

//Connect to the IMAP Server
$oClient->connect();

//Get all Mailboxes
/** @var \Vasim\IMAP\Support\FolderCollection $aFolder */
$aFolder = $oClient->getFolders();

//Loop through every Mailbox
/** @var \Vasim\IMAP\Folder $oFolder */
foreach($aFolder as $oFolder){

    //Get all Messages of the current Mailbox $oFolder
    /** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
    $aMessage = $oFolder->getMessages();

    /** @var \Vasim\IMAP\Message $oMessage */
    foreach($aMessage as $oMessage){
        echo $oMessage->subject.'';
        echo 'Attachments: '.$oMessage->getAttachments()->count().'';
        echo $oMessage->getHTMLBody(true);

        //Move the current Message to 'INBOX.read'
        if($oMessage->moveToFolder('INBOX.read') == true){
            echo 'Message has ben moved';
        }else{
            echo 'Message could not be moved';
        }
    }
}
```

There is an experimental function available to get a Folder instance by name. For an easier access please take a look at the new config option `imap.options.delimiter` however the `getFolder`method takes three options: the required (string) $folder\_name and two optional variables. An integer $attributes which seems to be sometimes 32 or 64 (I honestly have no clue what this number does, so feel free to enlighten me and anyone else) and a delimiter which if it isn't set will use the default option configured inside the [config/imap.php](src/config/imap.php) file.

```
/** @var \Vasim\IMAP\Client $oClient */

/** @var \Vasim\IMAP\Folder $oFolder */
$oFolder = $oClient->getFolder('INBOX.name');
```

Search for specific emails:

```
/** @var \Vasim\IMAP\Folder $oFolder */

//Get all messages since march 15 2018
/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->searchMessages([['SINCE', Carbon::parse('15.03.2018')]]);

//Get all messages containing "hello world"
/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->searchMessages([['TEXT', 'hello world']]);

//Get all unseen messages containing "hello world"
/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->searchMessages([['UNSEEN'], ['TEXT', 'hello world']]);
```

Available search criteria:

- `ALL` — return all messages matching the rest of the criteria
- `ANSWERED` — match messages with the \\ANSWERED flag set
- `BCC` "string" — match messages with "string" in the Bcc: field
- `BEFORE` "date" — match messages with Date: before "date"
- `BODY` "string" — match messages with "string" in the body of the message
- `CC` "string" — match messages with "string" in the Cc: field
- `DELETED` — match deleted messages
- `FLAGGED` — match messages with the \\FLAGGED (sometimes referred to as Important or Urgent) flag set
- `FROM` "string" — match messages with "string" in the From: field
- `KEYWORD` "string" — match messages with "string" as a keyword
- `NEW` — match new messages
- `OLD` — match old messages
- `ON` "date" — match messages with Date: matching "date"
- `RECENT` — match messages with the \\RECENT flag set
- `SEEN` — match messages that have been read (the \\SEEN flag is set)
- `SINCE` "date" — match messages with Date: after "date"
- `SUBJECT` "string" — match messages with "string" in the Subject:
- `TEXT` "string" — match messages with text "string"
- `TO` "string" — match messages with "string" in the To:
- `UNANSWERED` — match messages that have not been answered
- `UNDELETED` — match messages that are not deleted
- `UNFLAGGED` — match messages that are not flagged
- `UNKEYWORD` "string" — match messages that do not have the keyword "string"
- `UNSEEN` — match messages which have not been read yet

Further information:

-
-
-
-

Get a specific message by uid (Please note that the uid is not unique and can change):

```
/** @var \Vasim\IMAP\Folder $oFolder */

/** @var \Vasim\IMAP\Message $oMessage */
$oMessage = $oFolder->getMessage($uid = 1);
```

Flag or "unflag" a message:

```
/** @var \Vasim\IMAP\Message $oMessage */
$oMessage->setFlag(['Seen', 'Spam']);
$oMessage->unsetFlag('Spam');
```

Save message attachments:

```
/** @var \Vasim\IMAP\Message $oMessage */

/** @var \Vasim\IMAP\Support\AttachmentCollection $aAttachment */
$aAttachment = $oMessage->getAttachments();

$aAttachment->each(function ($oAttachment) {
    /** @var \Vasim\IMAP\Attachment $oAttachment */
    $oAttachment->save();
});
```

Fetch messages without body fetching (decrease load):

```
/** @var \Vasim\IMAP\Folder $oFolder */

/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->searchMessages([['TEXT', 'Hello world']], null, false);

/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->getMessages('ALL', null, false);
```

Fetch messages without body and attachment fetching (decrease load):

```
/** @var \Vasim\IMAP\Folder $oFolder */

/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->searchMessages([['TEXT', 'Hello world']], null, false, 'UTF-8', false);

/** @var \Vasim\IMAP\Support\MessageCollection $aMessage */
$aMessage = $oFolder->getMessages('ALL', null, false, false);
```

Find the folder containing a message:

```
$oFolder = $aMessage->getContainingFolder();
```

Documentation
-------------

[](#documentation)

### [Client::class](src/IMAP/Client.php)

[](#clientclass)

MethodArgumentsReturnDescriptionsetConfigarray $configselfSet the Client configuration. Take a look at `config/imap.php` for more inspiration.getConnectionresource $connectionresourceGet the current imap resourcesetReadOnlybool $readOnlyselfSet read only property and reconnect if it's necessary.setFetchOptioninteger $optionselfFail proof setter for $fetch\_optionisReadOnlyboolDetermine if connection is in read only mode.isConnectedboolDetermine if connection was established.checkConnectionDetermine if connection was established and connect if not.connectint $attemptsConnect to server.disconnectDisconnect from server.getFolderstring $folder\_name, int $attributes = 32, int or null $delimiterFolderGet a Folder instance by namegetFoldersbool $hierarchical, string or null $parent\_folderFolderCollectionGet folders list. If hierarchical order is set to true, it will make a tree of folders, otherwise it will return flat array.openFolderFolder $folder, integer $attemptsOpen a given folder.createFolderstring $namebooleanCreate a new folder.renameFolderstring $old\_name, string $new\_namebooleanRename a folder.deleteFolderstring $namebooleanDelete a folder.getMessagesFolder $folder, string $criteria, bool $fetch\_body, bool $fetch\_attachmentMessageCollectionGet messages from folder.getUnseenMessagesFolder $folder, string $criteria, bool $fetch\_body, bool $fetch\_attachmentMessageCollectionGet Unseen messages from folder.searchMessagesarray $where, Folder $folder, $fetch\_options, bool $fetch\_body, string $charset, bool $fetch\_attachmentMessageCollectionGet specific messages from a given folder.getQuotaarrayRetrieve the quota level settings, and usage statics per mailboxgetQuotaRootstring $quota\_rootarrayRetrieve the quota settings per usercountMessagesintGets the number of messages in the current mailboxcountRecentMessagesintGets the number of recent messages in current mailboxgetAlertsarrayReturns all IMAP alert messages that have occurredgetErrorsarrayReturns all of the IMAP errors that have occurredgetLastErrorstringGets the last IMAP error that occurred during this page requestexpungeboolDelete all messages marked for deletioncheckCurrentMailboxobjectCheck current mailbox### [Message::class](src/IMAP/Message.php)

[](#messageclass)

MethodArgumentsReturnDescriptionparseBodyMessageParse the Message bodydeleteDelete the current MessagerestoreRestore a deleted Messagecopystring $mailbox, int $optionsCopy the current Messages to a mailboxmovestring $mailbox, int $optionsMove the current Messages to a mailboxgetContainingFolderFolder or null $foldernullFoldermoveToFolderstring $mailbox, int $optionsMove the Message into an other FoldersetFlagstring or array $flagbooleanSet one or many flagsunsetFlagstring or array $flagbooleanUnset one or many flagshasTextBodyCheck if the Message has a text bodyhasHTMLBodyCheck if the Message has a html bodygetTextBodystringGet the Message text bodygetHTMLBodystringGet the Message html bodygetAttachmentsAttachmentCollectionGet all message attachmentshasAttachmentsbooleanChecks if there are any attachments presentgetClientClientGet the current Client instancegetUidstringGet the current UIDgetFetchOptionsstringGet the current fetch optiongetMsglistintegerGet the current message listgetHeaderInfoobjectGet the current header\_info objectgetHeaderstringGet the current raw headergetMessageIdintegerGet the current message IDgetMessageNointegerGet the current message numbergetSubjectstringGet the current subjectgetReferencesmixedGet any potentially present referencesgetDateCarbonGet the current date objectgetFromarrayGet the current from informationgetToarrayGet the current to informationgetCcarrayGet the current cc informationgetBccarrayGet the current bcc informationgetReplyToarrayGet the current reply to informationgetInReplyTostringGet the current In-Reply-TogetSenderarrayGet the current sender informationgetBodiesmixedGet the current bodiesgetRawBodymixedGet the current raw message bodyisbooleanDoes this message match another one?### [Folder::class](src/IMAP/Folder.php)

[](#folderclass)

MethodArgumentsReturnDescriptionhasChildrenboolDetermine if folder has children.setChildrenarray $childrenselfSet children.getMessageinteger $uid, integer or null $msglist, int or null fetch\_options, bool $fetch\_body, bool $fetch\_attachmentMessageGet a specific message from folder.getMessagesstring $criteria, bool $fetch\_body, bool $fetch\_attachmentMessageCollectionGet messages from folder.getUnseenMessagesstring $criteria, bool $fetch\_body, bool $fetch\_attachmentMessageCollectionGet Unseen messages from folder.searchMessagesarray $where, $fetch\_options, bool $fetch\_body, string $charset, bool $fetch\_attachmentMessageCollectionGet specific messages from a given folder.deleteDelete the current Mailboxmovestring $mailboxMove or Rename the current MailboxgetStatusinteger $optionsobjectReturns status information on a mailboxappendMessagestring $message, string $options, string $internal\_dateboolAppend a string message to the current mailboxgetClientClientGet the current Client instance### [Attachment::class](src/IMAP/Attachment.php)

[](#attachmentclass)

MethodArgumentsReturnDescriptiongetContentstring or nullGet attachment contentgetMimeTypestring or nullGet attachment mime typegetExtensionstring or nullGet a guessed attachment extensiongetNamestring or nullGet attachment namegetTypestring or nullGet attachment typegetDispositionstring or nullGet attachment dispositiongetContentTypestring or nullGet attachment content typegetImgSrcstring or nullGet attachment image source as base64 encoded data urlsavestring $path, string $filenamebooleanSave the attachment content to your filesystem### [MessageCollection::class](src/IMAP/Support/MessageCollection.php)

[](#messagecollectionclass)

Extends [Illuminate\\Support\\Collection::class](https://laravel.com/api/5.4/Illuminate/Support/Collection.html)

MethodArgumentsReturnDescriptionpaginateint $perPage = 15, $page = null, $pageName = 'page'LengthAwarePaginatorPaginate the current collection.### [AttachmentCollection::class](src/IMAP/Support/AttachmentCollection.php)

[](#attachmentcollectionclass)

Extends [Illuminate\\Support\\Collection::class](https://laravel.com/api/5.4/Illuminate/Support/Collection.html)

MethodArgumentsReturnDescriptionpaginateint $perPage = 15, $page = null, $pageName = 'page'LengthAwarePaginatorPaginate the current collection.### [FolderCollection::class](src/IMAP/Support/FolderCollection.php)

[](#foldercollectionclass)

Extends [Illuminate\\Support\\Collection::class](https://laravel.com/api/5.4/Illuminate/Support/Collection.html)

MethodArgumentsReturnDescriptionpaginateint $perPage = 15, $page = null, $pageName = 'page'LengthAwarePaginatorPaginate the current collection.### Known issues

[](#known-issues)

Milestones &amp; upcoming features
----------------------------------

[](#milestones--upcoming-features)

- Wiki!!

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- \[Vasim\]\[link-author\]
- \[All Contributors\]\[link-contributors\]

Supporters
----------

[](#supporters)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

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

Total

3

Last Release

1499d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/426c6b4af48368e867559aefca4e5a2da5347584bdb759a8eead779339d282f7?d=identicon)[vasim-seta](/maintainers/vasim-seta)

---

Top Contributors

[![vasim-seta](https://avatars.githubusercontent.com/u/85861303?v=4)](https://github.com/vasim-seta "vasim-seta (5 commits)")

---

Tags

mailcodeigniterimapvasimcodeigniter-imap

### Embed Badge

![Health badge](/badges/vasim-seta-codeigniter-imap/health.svg)

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

###  Alternatives

[php-imap/php-imap

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

1.7k13.2M48](/packages/php-imap-php-imap)[ddeboer/imap

Object-oriented IMAP for PHP

9184.0M14](/packages/ddeboer-imap)[webklex/php-imap

PHP IMAP client

4476.3M22](/packages/webklex-php-imap)[directorytree/imapengine

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

548243.6k7](/packages/directorytree-imapengine)[roopz/yii2-imap

yii2 extension to read and process mails from IMAP and PHP

4097.2k](/packages/roopz-yii2-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.

28137.9k3](/packages/henrique-borba-php-sieve-manager)

PHPackages © 2026

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