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

Read email headers and display the body as text

See more Email Object Examples

Read the sender, recipients, subject, date, and an optional custom header from an EML file. Display the plain-text body when available, or convert HTML to text. Handle messages that contain neither body format.

Chilkat CkPhp Downloads

CkPhp
<?php

include("chilkat.php");

$success = false;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

$email = new CkEmail();
$success = $email->LoadEml('with-attachments.eml');
if ($success != true) {
    print $email->lastErrorText() . "\n";
    exit;
}

print 'From: ' . $email->from() . "\n";
print 'Subject: ' . $email->subject() . "\n";
print 'Date: ' . $email->emailDateStr() . "\n";
$i = 0;
while (($i < $email->get_NumTo())) {
    print 'To: ' . $email->getToName($i) . '  ' . $email->getToAddr($i) . "\n";
    $i = $i + 1;
}

$referenceId = $email->getHeaderField('X-Reference-ID');
if ($email->get_LastMethodSuccess() == true) {
    print 'Reference: ' . $referenceId . "\n";
}

if ($email->HasPlainTextBody() == true) {
    print $email->getPlainTextBody() . "\n";
}
else {
    if ($email->HasHtmlBody() == true) {
        $reader = new CkHtmlToText();
        print $reader->toText($email->getHtmlBody()) . "\n";
    }
    else {
        print 'No text or HTML body.' . "\n";
    }

}


?>