CkPhp Requires Chilkat v11.0.0+
CkPhp
Create an HTML preview with embedded images
See more Email Object Examples
Make an independent copy of with-attachments.eml, remove ordinary file attachments from the copy, and export its HTML with related images as data URLs. The original retains its attachments. Use a sanitized viewer when showing untrusted HTML.
Chilkat CkPhp Downloads
<?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;
}
$preview = new CkEmail();
$success = $email->MakeCopy($preview);
if ($success != true) {
print $email->lastErrorText() . "\n";
exit;
}
// Keep related items: the HTML still refers to them.
$preview->DropAttachments();
print 'Files in original: ' . $email->get_NumAttachments() . ' Files in preview: ' . $preview->get_NumAttachments() . "\n";
if ($preview->HasHtmlBody() != true) {
print 'This message has no HTML preview.' . "\n";
exit;
}
$html = new CkStringBuilder();
$success = $preview->GetHtmlBodySb(true,$html);
if ($success != true) {
print $preview->lastErrorText() . "\n";
exit;
}
$success = $html->WriteFile('preview.html','utf-8',false);
if ($success != true) {
print 'Failed: html.WriteFile.' . "\n";
exit;
}
print 'Saved preview.html.' . "\n";
?>