javanile / php-imap2
PHP IMAP with OAUTH2
Requires
- php: >=7.0
- zbateson/mail-mime-parser: ^2.2
Requires (Dev)
- phpunit/phpunit: ^6.5
Suggests
- ext-iconv: For best support/performance
- ext-mbstring: For best support/performance
This package is auto-updated.
Last update: 2026-05-10 20:21:57 UTC
README
⭐ Give me a star, please! ⭐
PHP IMAP2
Modern IMAP extension wrapper for PHP with OAuth2 support.
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
- https://www.atmail.com/blog/imap-commands/
- https://developers.google.com/gmail/imap/xoauth2-protocol
- ddeboer/imap#443 (comment)
Support the Project
If this project helps you, consider supporting development:

