Skip to content

javanile/php-imap2

Repository files navigation

⭐ Give me a star, please! ⭐


Support PHP IMAP2
PHP IMAP2 Logo

PHP IMAP2

Modern IMAP extension wrapper for PHP with OAuth2 support.

Linter License PHP Version Packagist


Overview

php-imap2 provides a lightweight and modern interface for working with IMAP mailboxes in PHP, including OAuth2 authentication support for providers like Gmail and Outlook.

Designed as a simple drop-in alternative for projects that need secure IMAP access without legacy authentication.


Features

  • OAuth2 authentication support
  • Gmail IMAP integration
  • Outlook / Microsoft 365 support
  • Lightweight API
  • Compatible with native PHP IMAP workflows
  • Easy integration into existing projects

Requirements

  • PHP >= 7.0
  • PHP IMAP extension enabled

Installation

Install via Composer:

composer require javanile/php-imap2

Or download the latest release from GitHub.


Quick Start

<?php

$mbh = imap2_open(
    $server,
    $username,
    $token,
    OP_XOAUTH2
);

if (! $mbh) {
    error_log(imap2_last_error());

    throw new RuntimeException(
        'Unable to open the INBOX'
    );
}

Gmail OAuth2

Required OAuth scope:

https://mail.google.com/

Example IMAP server:

imap.gmail.com:993/imap/ssl

Microsoft Outlook / Office365

Example IMAP server:

outlook.office365.com:993/imap/ssl

OAuth2 authentication is supported using Microsoft identity platform access tokens.


Sandbox & Examples

Gmail Demo

Outlook Demo

Coming soon.


Error Handling

$error = imap2_last_error();

if ($error) {
    echo $error;
}

Contributing

Contributions, issues, and feature requests are welcome.

Feel free to open a pull request or start a discussion.


Contributors


Related Projects


References

Microsoft Outlook

IMAP & OAuth2


Support the Project

If this project helps you, consider supporting development:

👉 https://ko-fi.com/francescobianco

Packages

 
 
 

Contributors

Languages