PHPackages                             thingmabobby/imap-email-checker - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. thingmabobby/imap-email-checker

ActiveLibrary[HTTP &amp; Networking](/categories/http)

thingmabobby/imap-email-checker
===============================

A PHP class to fetch and process emails from an IMAP mailbox.

v2.0.0(11mo ago)79UnlicensePHPPHP ^8.0CI passing

Since Apr 27Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/thingmabobby/IMAPEmailChecker)[ Packagist](https://packagist.org/packages/thingmabobby/imap-email-checker)[ RSS](/packages/thingmabobby-imap-email-checker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)DependenciesVersions (5)Used By (0)

IMAPEmailChecker
================

[](#imapemailchecker)

A PHP class to fetch and process emails from an IMAP mailbox. This class provides functionalities to retrieve emails based on different criteria, check mailbox status, manage read/unread flags, perform custom searches, decode email bodies (including handling inline images), extract attachments, delete and archive emails.

Purpose
-------

[](#purpose)

This class is designed to simplify the process of accessing and managing emails via IMAP in PHP. It provides robust error handling using exceptions and can be used for various applications such as:

- **Email Archiving:** Storing emails in a database or other storage for record-keeping.
- **Automated Email Processing:** Building scripts to analyze incoming emails, trigger actions based on email content, or integrate email data into other systems.
- **Linking Emails to System Records:** Extracting specific identifiers (like ticket numbers, order IDs, or custom tags) directly from email subjects using a configurable regular expression to associate emails with records in your application (e.g., CRM, helpdesk, order management).
- **Email Backup Solutions:** Downloading and backing up emails from a mailbox.
- **Mailbox Monitoring:** Checking for new or unread emails and mailbox status using efficient methods.
- **Targeted Retrieval:** Searching for specific emails based on various criteria and fetching only those.

The class handles complexities like:

- **Robust Decoding:** Correctly decodes email bodies and headers in various encodings (e.g., Base64, Quoted-Printable) and normalizes text content to **UTF-8**.
- **Inline Image Embedding:** Automatically embeds inline images (referenced via `cid:`) within HTML email bodies as Base64 data URIs.
- **Attachment Extraction:** Provides access to *non-inline* email attachments.
- **UID Management:** Focuses on using Unique Identifiers (UIDs) for reliable message identification and efficient incremental retrieval.
- **Status Checks &amp; Flag Management:** Provides methods to check mailbox status efficiently and manage the `\Seen` (read/unread) flag.
- **Custom Search:** Allows flexible searching using standard IMAP criteria strings.
- **Exception-Based Errors:** Uses standard PHP exceptions (`RuntimeException`, `InvalidArgumentException`) to signal errors clearly.

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

[](#installation)

Composer:

```
composer require thingmabobby/imap-email-checker
```

Standalone:

```
require '..path/to/src/IMAPEmailChecker.php'; // Adjust path as needed
```

Usage
-----

[](#usage)

To use the IMAPEmailChecker class, you need to have the PHP IMAP extension enabled. Here's an extended example covering many common operations, demonstrating the use of try...catch for error handling:

```
