Sample code for 30+ languages & platforms
PHP Requires Chilkat v11.0.0+

Find the "Sent" IMAP Mailbox

See more IMAP Examples

Find the "Sent" IMAP mailbox. Also finds the Junk and Trash mailboxes..

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Imap;
use Chilkat2\Mailboxes;

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$imap = new Imap();

$imap->Ssl = true;
$imap->Port = 993;
try {
    $imap->Connect('imap.yourmailserver.com');

    // Login or authenticate in some way..
    $imap->Login('your_login', 'your_password');

    // Get the list of mailboxes.
    $refName = '';
    $wildcardedMailbox = '*';
    $subscribed = false;

    $mboxes = new Mailboxes();
    $imap->MbxList($subscribed, $refName, $wildcardedMailbox, $mboxes);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

// The mailbox with the "/Sent" flag is the "Sent" mailbox.
// Likewise for Junk and Trash..
$i = 0;
while ($i < $mboxes->Count) {
    if ($mboxes->HasFlag($i, '\Sent')) {
        echo 'Sent mailbox: ', $mboxes->GetName($i), "\n";
    }

    if ($mboxes->HasFlag($i, '\Junk')) {
        echo 'Junk mailbox: ', $mboxes->GetName($i), "\n";
    }

    if ($mboxes->HasFlag($i, '\Trash')) {
        echo 'Trash mailbox: ', $mboxes->GetName($i), "\n";
    }

    $i = $i + 1;
}

// Disconnect from the IMAP server.
$imap->Disconnect();