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

List Email UIDs

List the UIDs of each email in a mailbox.

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\Imap;
use Chilkat2\MessageSet;

$imap = new Imap();

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

// Connect to an IMAP server.
// Use TLS
$imap->Ssl = true;
$imap->Port = 993;
try {
    $imap->Connect('MY-IMAP-DOMAIN');

    // Login
    $imap->Login('MY-IMAP-LOGIN', 'MY-IMAP-PASSWORD');

    // Select an IMAP mailbox
    $imap->SelectMailbox('Inbox');

    // Get the message IDs of all the emails in the mailbox
    // We can choose to fetch UIDs or sequence numbers.
    $fetchUids = true;
    $messageSet = new MessageSet();
    $imap->QueryMbx('ALL', $fetchUids, $messageSet);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$i = 0;
$n = $messageSet->Count;
while ($i < $n) {
    echo $messageSet->GetId($i), "\n";
    $i = $i + 1;
}

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