Sample code for 30+ languages & platforms
PHP

Upload (Append) Email to an IMAP Mailbox

Upload / append an email to an IMAP mailbox.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Email;
use Chilkat2\Imap;

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

$imap = new Imap();

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

    // Login
    $imap->Login('myLogin', 'myPassword');

    $email = new Email();

    // Load the email from a .eml file.
    $email->LoadEml('myEmail.eml');

    $imap->AppendMail('Inbox', $email);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

echo "Email uploaded to Inbox!\n";

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