PHP Requires Chilkat v11.0.0+
PHP
Delete IMAP Email
To delete an email, the "Deleted" flag must be set to 1 for each message to be deleted. You must also call Expunge or ExpungeAndClose to remove the emails marked as deleted.Chilkat PHP Downloads
<?php
use Chilkat2\Imap;
use Chilkat2\MessageSet;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// This example deletes email matching a criteria from Inbox.
$imap = new Imap();
// Turn on session logging:
$imap->KeepSessionLog = true;
// Connect to an IMAP server.
// Use TLS
$imap->Ssl = true;
$imap->Port = 993;
try {
$imap->Connect('imap.example.com');
// Login
$imap->Login('myLogin', 'myPassword');
// Select an IMAP mailbox
$imap->SelectMailbox('Inbox');
$fetchUids = true;
// Get the message IDs for all emails having "FTP2" in the subject.
$messageSet = new MessageSet();
$imap->QueryMbx('SUBJECT FTP2', $fetchUids, $messageSet);
// Set the Deleted flag for each message:
$imap->SetFlags($messageSet, 'Deleted', 1);
// Expunge and close the mailbox.
$imap->ExpungeAndClose();
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Display the session log.
echo $imap->SessionLog, "\n";
// Disconnect from the IMAP server.
$imap->Disconnect();