webklex / php-imap
PHP IMAP client
Fund package maintenance!
Ko Fi
www.buymeacoffee.com/webklex
Installs: 2 535 728
Dependents: 9
Suggesters: 0
Security: 1
Stars: 314
Watchers: 13
Forks: 147
Open Issues: 140
Requires
- php: ^8.0.2
- ext-fileinfo: *
- ext-iconv: *
- ext-json: *
- ext-libxml: *
- ext-mbstring: *
- ext-openssl: *
- ext-zip: *
- illuminate/pagination: >=5.0.0
- nesbot/carbon: ^2.62.1
- symfony/http-foundation: >=2.8.0
Requires (Dev)
- phpunit/phpunit: ^9.5.10
Suggests
- symfony/mime: Recomended for better extension support
- symfony/var-dumper: Usefull tool for debugging
- 5.5.0
- 5.4.0
- 5.3.0
- 5.2.0
- 5.1.0
- 5.0.1
- 5.0.0
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.2
- 4.0.1
- 4.0.0
- 3.2.0
- 3.1.0-alpha
- 3.0.0-alpha
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.0
- 2.5.1
- 2.5.0
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.1
- 2.3.0
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.13
- 2.1.12
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.4.5
- 1.4.2.1
- 1.4.2
- dev-master / 1.0.x-dev
- 0.0.3
- 0.0.2
- 0.0.1
This package is auto-updated.
Last update: 2024-11-11 08:02:30 UTC
README
Description
PHP-IMAP is a wrapper for common IMAP communication without the need to have the php-imap module installed / enabled.
The protocol is completely integrated and therefore supports IMAP IDLE operation and the "new" oAuth authentication
process as well.
You can enable the php-imap
module in order to handle edge cases, improve message decoding quality and is required if
you want to use legacy protocols such as pop3.
Official documentation: php-imap.com
Laravel wrapper: webklex/laravel-imap
Discord: discord.gg/rd4cN9h6
Table of Contents
- Documentations
- Compatibility
- Basic usage example
- Sponsors
- Testing
- Known issues
- Support
- Features & pull requests
- Security
- Credits
- License
Documentations
- Legacy (< v2.0.0): legacy documentation
- Core documentation: php-imap.com
Compatibility
Basic usage example
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 be tested in real life and is only meant to give an impression on how things work.
use Webklex\PHPIMAP\ClientManager; require_once "vendor/autoload.php"; $cm = new ClientManager('path/to/config/imap.php'); /** @var \Webklex\PHPIMAP\Client $client */ $client = $cm->account('account_identifier'); //Connect to the IMAP Server $client->connect(); //Get all Mailboxes /** @var \Webklex\PHPIMAP\Support\FolderCollection $folders */ $folders = $client->getFolders(); //Loop through every Mailbox /** @var \Webklex\PHPIMAP\Folder $folder */ foreach($folders as $folder){ //Get all Messages of the current Mailbox $folder /** @var \Webklex\PHPIMAP\Support\MessageCollection $messages */ $messages = $folder->messages()->all()->get(); /** @var \Webklex\PHPIMAP\Message $message */ foreach($messages as $message){ echo $message->getSubject().'<br />'; echo 'Attachments: '.$message->getAttachments()->count().'<br />'; echo $message->getHTMLBody(); //Move the current Message to 'INBOX.read' if($message->move('INBOX.read') == true){ echo 'Message has been moved'; }else{ echo 'Message could not be moved'; } } }
Sponsors
Testing
To run the tests, please execute the following command:
composer test
Quick-Test / Static Test
To disable all test which require a live mailbox, please copy the phpunit.xml.dist
to phpunit.xml
and adjust the configuration:
<php> <env name="LIVE_MAILBOX" value="false"/> </php>
Full-Test / Live Mailbox Test
To run all tests, you need to provide a valid imap configuration.
To provide a valid imap configuration, please copy the phpunit.xml.dist
to phpunit.xml
and adjust the configuration:
<php> <env name="LIVE_MAILBOX" value="true"/> <env name="LIVE_MAILBOX_DEBUG" value="true"/> <env name="LIVE_MAILBOX_HOST" value="mail.example.local"/> <env name="LIVE_MAILBOX_PORT" value="993"/> <env name="LIVE_MAILBOX_VALIDATE_CERT" value="false"/> <env name="LIVE_MAILBOX_QUOTA_SUPPORT" value="true"/> <env name="LIVE_MAILBOX_ENCRYPTION" value="ssl"/> <env name="LIVE_MAILBOX_USERNAME" value="root@example.local"/> <env name="LIVE_MAILBOX_PASSWORD" value="foobar"/> </php>
The test account should not contain any important data, as it will be deleted during the test. Furthermore, the test account should be able to create new folders, move messages and should not be used by any other application during the test.
It's recommended to use a dedicated test account for this purpose. You can use the provided Dockerfile
to create an imap server used for testing purposes.
Build the docker image:
cd .github/docker docker build -t php-imap-server .
Run the docker image:
docker run --name imap-server -p 993:993 --rm -d php-imap-server
Stop the docker image:
docker stop imap-server
Known issues
Support
If you encounter any problems or if you find a bug, please don't hesitate to create a new issue. However, please be aware that it might take some time to get an answer. Off-topic, rude or abusive issues will be deleted without any notice.
If you need commercial support, feel free to send me a mail at github@webklex.com.
A little notice
If you write source code in your issue, please consider to format it correctly. This makes it so much nicer to read
and people are more likely to comment and help :)
```php
echo 'your php code...';
```
will turn into:
echo 'your php code...';
Features & pull requests
Everyone can contribute to this project. Every pull request will be considered, but it can also happen to be declined.
To prevent unnecessary work, please consider to create a feature issue
first, if you're planning to do bigger changes. Of course, you can also create a new feature issue
if you're just wishing a feature ;)
Change log
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security related issues, please email github@webklex.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.