2016-05-01 13:09:24 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This example shows sending a DKIM-signed message with PHPMailer.
|
|
|
|
* More info about DKIM can be found here: http://www.dkim.org/info/dkim-faq.html
|
2016-06-06 14:33:29 +02:00
|
|
|
* There's more to using DKIM than just this code - check out this article:
|
2016-08-29 10:21:39 +02:00
|
|
|
* @see https://yomotherboard.com/how-to-setup-email-server-dkim-keys/
|
2016-06-06 14:33:29 +02:00
|
|
|
* See also the DKIM_gen_keys example code in the examples folder,
|
|
|
|
* which shows how to make a key pair from PHP.
|
2016-05-01 13:09:24 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
//Import the PHPMailer class into the global namespace
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
|
|
|
|
require '../vendor/autoload.php';
|
|
|
|
|
|
|
|
//Usual setup
|
|
|
|
$mail = new PHPMailer;
|
|
|
|
$mail->setFrom('from@example.com', 'First Last');
|
|
|
|
$mail->addAddress('whoto@example.com', 'John Doe');
|
|
|
|
$mail->Subject = 'PHPMailer mail() test';
|
2017-09-29 16:07:42 +02:00
|
|
|
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
|
2016-05-01 13:09:24 +02:00
|
|
|
|
2016-06-06 14:33:29 +02:00
|
|
|
//This should be the same as the domain of your From address
|
|
|
|
$mail->DKIM_domain = 'example.com';
|
2016-05-01 13:09:24 +02:00
|
|
|
//See the DKIM_gen_keys.phps script for making a key pair -
|
|
|
|
//here we assume you've already done that.
|
|
|
|
//Path to your private key:
|
2016-06-06 14:33:29 +02:00
|
|
|
$mail->DKIM_private = 'dkim_private.pem';
|
|
|
|
//Set this to your own selector
|
2016-05-01 13:09:24 +02:00
|
|
|
$mail->DKIM_selector = 'phpmailer';
|
|
|
|
//Put your private key's passphrase in here if it has one
|
|
|
|
$mail->DKIM_passphrase = '';
|
2016-06-06 14:33:29 +02:00
|
|
|
//The identity you're signing as - usually your From address
|
|
|
|
$mail->DKIM_identity = $mail->From;
|
2018-06-26 17:04:38 +02:00
|
|
|
//Suppress listing signed header fields in signature, defaults to true for debugging purpose
|
2018-10-30 08:40:02 +01:00
|
|
|
$mail->DKIM_copyHeaderFields = false;
|
2018-06-26 17:04:38 +02:00
|
|
|
//Optionally you can add extra headers for signing to meet special requirements
|
2018-10-30 08:40:02 +01:00
|
|
|
$mail->DKIM_extraHeaders = ['List-Unsubscribe', 'List-Help'];
|
2016-05-01 13:09:24 +02:00
|
|
|
|
|
|
|
//When you send, the DKIM settings will be used to sign the message
|
2016-06-06 14:33:29 +02:00
|
|
|
if (!$mail->send()) {
|
2019-10-08 13:35:03 +02:00
|
|
|
echo 'Mailer Error: '. $mail->ErrorInfo;
|
2016-06-06 14:33:29 +02:00
|
|
|
} else {
|
2019-10-08 13:35:03 +02:00
|
|
|
echo 'Message sent!';
|
2016-06-06 14:33:29 +02:00
|
|
|
}
|