Sample code for 30+ languages & platforms
PHP 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 Downloads

PHP
<?php

use Chilkat2\Email;

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

$original = new Email();
try {
    $original->LoadEml('message.eml');

    $email = new Email();
    $email->From = 'Sam Lee <sam@example.com>';
    $email->AddTo('Alex Rivera', 'alex@example.net');

    $email->Subject = 'Forwarded message';
    $email->Body = 'The original email is attached.';
    $email->AttachEmail($original);

    $email->SaveEml('forward-as-attachment.eml');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

echo "Saved forward-as-attachment.eml.\n";