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

Forward an email as an attachment

See more Email Object Examples

Attach the original Email to a new message as a message/rfc822 part. The recipient can open the attached email and read its original headers and body.

Chilkat PHP ActiveX Downloads

PHP ActiveX
<?php

$success = 0;

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

$original = new COM("Chilkat.Email");
$success = $original->LoadEml('message.eml');
if ($success != 1) {
    print $original->LastErrorText . "\n";
    exit;
}

$email = new COM("Chilkat.Email");
$email->From = 'Sam Lee <sam@example.com>';
$success = $email->AddTo('Alex Rivera','alex@example.net');
if ($success != 1) {
    print $email->LastErrorText . "\n";
    exit;
}

$email->Subject = 'Forwarded message';
$email->Body = 'The original email is attached.';
$success = $email->AttachEmail($original);
if ($success != 1) {
    print $email->LastErrorText . "\n";
    exit;
}

$success = $email->SaveEml('forward-as-attachment.eml');
if ($success != 1) {
    print $email->LastErrorText . "\n";
    exit;
}

print 'Saved forward-as-attachment.eml.' . "\n";

?>