Skip to content

Instantly share code, notes, and snippets.

@gamalan
Created August 30, 2018 02:18
Show Gist options
  • Save gamalan/b79877d0654a710a290abe871661d3fe to your computer and use it in GitHub Desktop.
Save gamalan/b79877d0654a710a290abe871661d3fe to your computer and use it in GitHub Desktop.
SwiftMailer DKIM Sign
<?php
require 'vendor/autoload.php';
$transport = Swift_SmtpTransport::newInstance('localhost', 25);
$mailer = Swift_Mailer::newInstance($transport);
// Read private key file
$privateKey = file_get_contents('/path/to/privatekey');
$domainName = 'example.com';
$selector = 'default';
$signer = new Swift_Signers_DKIMSigner($privateKey, $domainName, $selector);
// Create Message
$message = Swift_Message::newInstance();
// Attach signer
$message->attachSigner($signer);
$message
->setFrom(['[email protected]'])
->setTo(['[email protected]'])
->setSubject('Hello World')
->setBody('Hello World')
;
$result = $mailer->send($message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment