https://github.com/dcblogdev/imap
IMAP class for reading imap emails with PHP
https://github.com/dcblogdev/imap
hacktoberfest imap php
Last synced: 11 months ago
JSON representation
IMAP class for reading imap emails with PHP
- Host: GitHub
- URL: https://github.com/dcblogdev/imap
- Owner: dcblogdev
- License: mit
- Created: 2016-11-27T10:41:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-07-21T14:32:45.000Z (over 3 years ago)
- Last Synced: 2025-03-31T22:23:49.988Z (about 1 year ago)
- Topics: hacktoberfest, imap, php
- Language: PHP
- Homepage:
- Size: 20.5 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
[](https://packagist.org/packages/dcblogdev/imap)
[](https://packagist.org/packages/dcblogdev/imap)

IMAP class for reading IMAP emails with PHP
# Example usage:
```php
use Dcblogdev\Imap\Imap;
//set search criteria
$date = date('d-M-y', strtotime('1 week ago'));
$term = 'ALL UNDELETED SINCE "'.$date.'"';
//ignore array of emails
$exclude = [];
$email = 'someone@domain.com';
$password = 'emailpassword';
$host = 'outlook.office365.com';//your email host
$port = '993';//port number
$savePath = "emails";//folder to save attachments
$markAsSeen = true;//when true mark email as been read
$delete = false;//set to true to delete email
//initialise email
$imap = new Imap($email, $password, $host, $port, 'Inbox', $savePath, $markAsSeen, $delete);
//get emails pass in the search term and exclude array
$emails = $imap->emails($term, $exclude);
//loop over emails and display
foreach($emails as $email) {
echo "Account {$email['account']}
";
echo "Subject {$email['subject']}
";
echo "From {$email['fromName']} ({$email['fromAddress']})
";
echo "To {$email['toAddress']}
";
echo "CC {$email['ccAddress']}
";
echo "Date {$email['emailDate']}
";
echo count($email['attachments'])." Attachments
";
foreach($email['attachments'] as $attachment) {
echo "{$attachment['fileName']}";
}
echo "
";
if ($email['htmlBody'] !='') {
echo $email['htmlBody'];
} else {
echo nl2br($email['plainBody']);
}
echo "
";
}
```