PHP Requires Chilkat v11.0.0+
PHP
Sign an email and send the signed bytes over SMTP
See more DKIM Examples
Compose the email, render it to MIME once, add its DKIM signature, and submit those same bytes to an SMTP server. Put blind-copy recipients in the SMTP envelope only so their addresses stay out of the visible headers.
Use an authorized SMTP account and your own sender domain. Publish the selector’s matching public key first. If your relay rewrites signed content, have it apply the signature after its final edits. A successful SMTP submission means the relay accepted the message. A recipient can then verify it with the public key in DNS.
Chilkat PHP Downloads
<?php
use Chilkat2\BinData;
use Chilkat2\Dkim;
use Chilkat2\Email;
use Chilkat2\MailMan;
use Chilkat2\PrivateKey;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
$mail = new MailMan();
$mail->SmtpHost = 'smtp.example.com';
$mail->SmtpPort = 465;
$mail->SmtpSsl = true;
$mail->RequireSslCertVerify = true;
$mail->SmtpUsername = 'SMTP_USERNAME';
$mail->SmtpPassword = 'SMTP_PASSWORD';
$email = new Email();
$email->From = 'Workshop team <updates@example.com>';
$email->Subject = 'Workshop registration';
$email->Body = 'Registration opens on Monday.';
try {
$email->AddTo('Newsletter editor', 'editor@example.net');
// Render after all headers, recipients, and content are final.
$message = new BinData();
$mail->RenderToMimeBd($email, $message);
// Supply your RSA signing key. For an encrypted PEM, get its password from your credential store.
$privateKey = new PrivateKey();
$privateKey->LoadAnyFormatFile('dkim-private.pem', '');
$signer = new Dkim();
$signer->DkimDomain = 'example.com';
$signer->DkimSelector = 'mail2026';
$signer->DkimAlg = 'rsa-sha256';
$signer->SetDkimPrivateKey($privateKey);
$signer->DkimSign($message);
// archive@example.com is an envelope-only blind copy.
$recipients = 'editor@example.net,archive@example.com';
$mail->SendMimeBd('updates@example.com', $recipients, $message);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
echo "SMTP relay accepted the signed message.\n";
try {
$mail->CloseSmtpConnection();
} catch (\Chilkat2\Exception $e) {
echo "The SMTP session did not close cleanly.\n";
}