PHP
Chilkat2 PHP
Unsubscribe from an IMAP Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.Unsubscribe method, which removes the subscription to a mailbox. The mailbox itself and its messages are not deleted. This example unsubscribes from a mailbox.
Background: Unsubscribing simply drops a mailbox from the account's subscription list, so clients that show only subscribed folders will stop displaying it — the folder and everything in it remain on the server untouched. This is the counterpart to
Subscribe, and is how you declutter a mailbox listing without deleting anything (deleting a folder is DeleteMailbox).Chilkat PHP Downloads
<?php
use Chilkat2\Imap;
// Demonstrates the Imap.Unsubscribe method, which removes the subscription to a mailbox.
// The mailbox itself and its messages are not deleted.
$imap = new Imap();
$imap->Ssl = true;
$imap->Port = 993;
try {
$imap->Connect('imap.example.com');
$imap->Login('user@example.com', 'myPassword');
// Remove the subscription to a mailbox (the mailbox is not deleted).
$imap->Unsubscribe('Archive2026');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
echo "Unsubscribed from the mailbox.\n";
try {
$imap->Disconnect();
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}