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

Set a MIME header on one attachment

See more Email Object Examples

Add a file using the content type required by the receiving application. Set Content-Description on the newly added MIME part and read it back from that part. The message-level headers have a separate collection.

Chilkat PHP ActiveX Downloads

PHP ActiveX
<?php

$success = 0;

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

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

$email->Subject = 'Workshop registration';
$email->Body = 'Attached is the requested data file.';
$success = $email->AddFileAttachment2('sample.hpm','application/x-hprimnet');
if ($success != 1) {
    print $email->LastErrorText . "\n";
    exit;
}

$index = $email->NumAttachments - 1;
$email->AddAttachmentHeader($index,'Content-Description','HPM/3.0');
print $email->getAttachmentHeader($index,'Content-Description') . "\n";

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

print 'Saved described-attachment.eml.' . "\n";

?>