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

Download POP3 Email to MIME

Download the email from a POP3 mailbox directly into MIME, without parsing into email objects.

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\BinData;
use Chilkat2\Email;
use Chilkat2\MailMan;
use Chilkat2\StringTable;

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

// The mailman object is used for receiving (POP3)
// and sending (SMTP) email.
$mailman = new MailMan();

// Set the POP3 server's hostname
$mailman->MailHost = 'pop.example.com';

// Set the POP3 login/password.
$mailman->PopUsername = 'myLogin';
$mailman->PopPassword = 'myPassword';

// First, get the complete set of UIDLs for the email in the POP3 mailbox:
$stUidls = new StringTable();
try {
    $mailman->FetchUidls($stUidls);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

// Download each email as MIME.
// If desired, the MIME can be loaded into an email object.
$bdMime = new BinData();
$email = new Email();

$count = $stUidls->Count;
$i = 0;
while ($i < $count) {
    try {
        $mailman->FetchMimeBd($stUidls->StringAt($i), $bdMime);
    } catch (\Chilkat2\Exception $e) {
        echo $e->getMessage(), "\n";
        exit;
    }

    $email->SetFromMimeBd($bdMime);
    echo 'From: ', $email->From, "\n";
    echo 'Subject: ', $email->Subject, "\n";

    $i = $i + 1;
}