haogood / php-imap
Get email contents and attachments using php imap extension.
v1.0.1
2018-03-15 16:11 UTC
Requires
- php: >=5.5.0
- ext-imap: *
This package is not auto-updated.
Last update: 2025-05-26 02:56:21 UTC
README
Requirements
- PHP >= 5.5.0
- IMAP PHP Extension
Installation
composer require haogood/php-imap
Initialize
use IMAP\IMAPMailbox; $host = '{imap.gmail.com:993/imap/ssl}'; $user = 'user@gmail.com'; $pwd = '******'; $mailbox = new IMAPMailbox($host, $user, $pwd);
Search
$emails = $mailbox->search('ALL');
Fetch header info
foreach ($emails as $email) { // Header info $headerinfo = $email->fetchHeaderinfo(); // Author $author = $headerinfo->from->personal; // Sender address $from = $headerinfo->from->mailbox.'@'.$headerinfo->from->host; // Timestamp $timstamp = $headerinfo->udate; // Contents $contents = $email->getBody(); }
Fetch attachments
foreach ($emails as $email) { foreach($email->getAttachments() as $attachment) { // Filename $filename = $attachment->getFilename(); // Extension $ext = $attachment->getExtension(); // Attachment file $file = $attachment->getBody(); // Attchment info $info = $attachment->getInfo(); } }
Reference
License
haogood/php-imap
is licensed under The MIT License (MIT).