IMAP class for reading imap emails with PHP

Fund package maintenance!
dcblogdev

v1.0.3 2022-07-21 12:49 UTC

This package is auto-updated.

Last update: 2024-04-21 18:12:28 UTC


README

Latest Version on Packagist Total Downloads

Logo

IMAP class for reading IMAP emails with PHP

Example usage:

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']}<br>";
	echo "Subject {$email['subject']}<br>";
	echo "From {$email['fromName']} ({$email['fromAddress']})<br>";
	echo "To {$email['toAddress']}<br>";
	echo "CC {$email['ccAddress']}<br>";
	echo "Date {$email['emailDate']}<br>";
	echo count($email['attachments'])." Attachments<br>";

	foreach($email['attachments'] as $attachment) {
		echo "<a href='{$attachment['file']}'>{$attachment['fileName']}</a>";
	}

	echo "<br><br>";
	if ($email['htmlBody'] !='') {
		echo $email['htmlBody'];
	} else {
		echo nl2br($email['plainBody']);
	}
	echo "<hr>";
}