PHPackages                             razzbee/php-libimap - 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. razzbee/php-libimap

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

razzbee/php-libimap
===================

A PHP IMAP library in Pure OOP for ease and simplicity

v1.0.1-alpha(9y ago)152Apache-2.0PHPPHP &gt;=5.4

Since Sep 4Pushed 7y ago1 watchersCompare

[ Source](https://github.com/razzbee/php-libimap)[ Packagist](https://packagist.org/packages/razzbee/php-libimap)[ Docs](https://github.com/razzbee/php-libimap)[ RSS](/packages/razzbee-php-libimap/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)DependenciesVersions (2)Used By (0)

php-libimap
===========

[](#php-libimap)

php-libimap is a PHP imap library in pure OOP, the idea is to make the native php\_imap functions easier to use with performance tunning in mind.

### Installation

[](#installation)

using composer , include this in your ***composer.json*** file :

```
"razzbee/php-libimap" : "dev-master"
```

### Usage

[](#usage)

#### Initialize class

[](#initialize-class)

```
$imap = new \PHPLibImap\IMAP;
```

**connect an imap server**

```
$imap->connectServer([
   'host' => 'localhost',
   'port' => 993,
   'imap_username' => 'username@domain.tld',
   'password' => 'secret',
   'mailbox_name' => 'INBOX',
   'enableSSL' => true,
]);
```

**host** : Your Imap mail server hostname , example : localhost , 19.10.10.2 , imap.domain.tld or domain.tld

**port** : your mailserver's imap's port , the default for secure connection is 993 and no secure connection is 143

**imap\_username** : The full qualified email address of mail account , example:

**password** : your mail account password.

**mailbox\_name** : (optional) , the mailbox to open on an initial connection, if non is specified, INBOX will be used.

**enableSSL** : (optional) , This is for those using a custom port, so that the library will know if the port needs a secure connection

### Switching Mailbox

[](#switching-mailbox)

After Connecting to the server, the optional mailbox\_name supplied in the connection parameters is opened automatically , you can change or switch mailbox using

```
$imap-> switchMailBox('mailbox_name');
```

the mailbox\_name must be one of the names of the mailfolders or boxes in your mailserver , example: INBOX , Drafts , Spam or Trash

### Fetch MailBoxes (Mail Folders)

[](#fetch-mailboxes-mail-folders)

You can also list available mail boxes in mailserver

```
$mailBoxes = $imap->getMailBoxes($pattern);
```

$pattern: (optional) This is either \* or % where :

\* Means the library should fetch all the mailboxes including top level mail boxes and sub folders

**%** Means the library should fetch all sub folders in the current mailbox

read more here :

### Get Info About a mailbox

[](#get-info-about-a-mailbox)

```
$mailBoxInfo = $imap->getMailBoxInfo($mailboxName=null,$forceNew=false);
```

**$mailBoxName**: (optional) the name of the mailbox you want the info about, it defaults to the current opened mailbox if not set

**$forceNew** : (optional) The mailbox info is always prefetched and kept, but if you want a fresh copy of the info to be refetched , set this to true ..

***Count Total Recent Messages***

```
$totalRecent = $imap->getMailBoxInfo()->recent;
```

### Count Total Unread Messages In the MailBox

[](#count-total-unread-messages-in-the-mailbox)

```
$totalMsgNo = $imap->getTotalMessages();

//or

$totalMsgNo = $imap->getMailBoxInfo()->messages;
```

### Fetch Mails From a MailBox

[](#fetch-mails-from-a-mailbox)

This library has many ways to fetch mails from a mailbox , we have also optimized this particular feature for speed and performance ..

#### Fetch MailBox Items overview By UID

[](#fetch-mailbox-items-overview-by-uid)

```
$mails = $imap->fetchMailBoxItems("mailbox_name")
              ->select(uid1,uid2,uid3,uid4...uidN)
			  ->getResults();
```

**mailbox\_name** : optional mailbox name , if none is supplied, the current opened mailboxed will be used

**select(uid1,uid2, ... )**: Select mail headers by the uid or the integer id(s) of the mail(s) , you must provide a valid uid else an exception will be generated

**getResults** : Generate and get the results

#### Fetch Mail Overview using range

[](#fetch-mail-overview-using-range)

```
$mails = $imap->fetchMailBoxItems("mailbox_name")
              ->range(1,10)
			  ->orderById('desc')
			  ->getResults();
```

**range(arg1,arg2)** : The range of mail uid , the above example will pull mailbox item overview info of uid 1 to 10 , This method assumes you already know your range already..

**orderById** : Order the results by the uid , the default is DESC (Descending Order), this means the latest mails overview info will be shown first

#### Fetch Mail Overview using limit and Offset

[](#fetch-mail-overview-using-limit-and-offset)

Like mysql limit and offset , this library supports the limit and offset using the limit($limit,$offset) method..

```
$mails = $imap->fetchMailBoxItems("mailbox_name")
              ->limit(1,10)
			  ->orderById('desc')
			  ->getResults();
```

***limit($limit,$offset=0)*** : The limit method accepts two arguments the limit and offset ,internally , the limits and offsets are been calculated automatically to ranges , this method is safer to use if you have no idea about the range values or number of data in the mailbox. The offset is optional and defaults to 0

#### Move Mail Between Mailboxes

[](#move-mail-between-mailboxes)

This method moves email message between mailboxes or folder, on success true is returned else false,an exception will also occur on error ..

```
$move = $imap->moveMail($mails_uids_array,$source_mailbox,$destination_mailbox,$expunge=false);
```

***$mails\_uids\_array*** : The mail(s) numeric uid in an array , it can contain 1 or more valid ids

***$source\_mailbox*** : The name of the mailbox where the mail is currently located at , example : INBOX , Drafts ...

***$destination\_mailbox*** : The Name of the new mail box you want to move the mail into , Example : Spam, drafts ....

***$expunge*** : Optional boolean which tells the library to perform immediate clean up or deletion of the email at the source mailbox after moving

\###Mark as Mail as seen , answered , deleted , draft or flagged

```
$setFlag = $imap->setFlag($mails_uids_array,$flag,$mailBoxName);
```

***$mails\_uids\_array*** : The mail(s) numeric uid in an array , it can contain 1 or more valid ids

***$flag***: The flag to set to ,valid flags : seen , answered, deleted , draft or flagged

***$mailBoxName*** : Mailbox name of the mails you want to set the flags to if not provided , current opened mailbox will be used

#### Search Mail

[](#search-mail)

Search into mailbox using a given criteria , use the getResults() method to retrive the results

```
        $keyword = "hello";

        //body must contain at least one occurrance of the keyword
        $searchCritiria['BODY'] = $keyword;

        //subject too must contain at least one occurrance of the keyword
        $searchCritiria['SUBJECT'] = $keyword;

		$mailBoxName = "INBOX";

        $searchResults = $imap
            ->search($searchCritiria,$mailBoxName)
            ->limit(20)
            ->getResults();
```

***$keyword*** The string we want to search for ***$searchCritiria*** : The search Criteria which will be used for the search , read more about the criteria here :

***$mailBoxName***: Optional Mailbox Name where you want to search into , if the mailbox name is omitted , the current opened mailbox will be used

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

3539d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/83fd97c54fd92d9d9500a10a4a5827f1f00ca807695b82f0c1ff889131f4151e?d=identicon)[razzbee](/maintainers/razzbee)

---

Top Contributors

[![razzbee](https://avatars.githubusercontent.com/u/3003019?v=4)](https://github.com/razzbee "razzbee (46 commits)")

---

Tags

phpmailphp-imapphp libimapPHP Imap LibraryPHP Imap mailImap Client

### Embed Badge

![Health badge](/badges/razzbee-php-libimap/health.svg)

```
[![Health](https://phpackages.com/badges/razzbee-php-libimap/health.svg)](https://phpackages.com/packages/razzbee-php-libimap)
```

###  Alternatives

[webklex/php-imap

PHP IMAP client

4365.5M14](/packages/webklex-php-imap)[railsware/mailtrap-php

The Mailtrap SDK provides methods for all API functions.

56770.5k](/packages/railsware-mailtrap-php)[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)[shuchkin/react-smtp-client

ReactPHP async SMTP Client

245.7k](/packages/shuchkin-react-smtp-client)

PHPackages © 2026

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