1. Go to this page and download the library: Download kekaadrenalin/yii2-imap library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$mailIds = $mailbox->searchMailBox(); // Gets all Mail ids.
print_r($mailIds);
$mailbox->readMailParts = false;
foreach($mailIds as $mailId)
{
// Returns Mail contents
$mail = $mailbox->getMail($mailId);
// Read mail parts (plain body, html body and attachments
$mailObject = $mailbox->getMailParts($mail);
// Array with IncomingMail objects
print_r($mailObject);
// Returns mail attachements if any or else empty array
$attachments = $mailObject->getAttachments();
foreach($attachments as $attachment){
echo ' Attachment:' . $attachment->name . PHP_EOL;
// Delete attachment file
unlink($attachment->filePath);
}
}
$mailbox->deleteMail($mailId); // Mark a mail to delete
$mailbox->expungeDeletedMails(); // Deletes all marked mails
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.