PHP ActiveX
PHP ActiveX
S/MIME Encrypt .eml without Sending
See more Email Object Examples
Demonstrates how to encrypt an email using the recipient's digital certificate. This example just encrypts, and does not send the email.Chilkat PHP ActiveX Downloads
<?php
$success = 0;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$email = new COM("Chilkat.Email");
$success = $email->LoadEml('c:/temp/email/unencrypted.eml');
if ($success == 0) {
print $email->LastErrorText . "\n";
exit;
}
// The email content is encrypted using AES with a 256-bit key, operating in GCM mode, which provides authenticated encryption.
$email->Pkcs7CryptAlg = 'aes-gcm';
$email->Pkcs7KeyLength = 256;
$email->OaepPadding = 1;
$email->OaepHash = 'sha256';
$email->OaepMgfHash = 'sha256';
$cert = new COM("Chilkat.Cert");
$success = $cert->LoadFromFile('c/temps/cert/recipient.cer');
if ($success == 0) {
print $cert->LastErrorText . "\n";
exit;
}
$email->SendEncrypted = 1;
$email->SetEncryptCert($cert);
$sbSmime = new COM("Chilkat.StringBuilder");
// The mailman object applies the encryption by rendering the email according to the instructions (property settings) provided in the email object.
// No email is sent.
$mailman = new COM("Chilkat.MailMan");
$success = $mailman->RenderToMimeSb($email,$sbSmime);
if ($success == 0) {
print $mailman->LastErrorText . "\n";
exit;
}
$success = $sbSmime->WriteFile('c:/temp/encryptedEmail.eml','utf-8',0);
if ($success == 0) {
print $mailman->LastErrorText . "\n";
exit;
}
print 'Success!' . "\n";
?>