0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-19 17:42:14 +02:00
PHPMailer/examples/DKIM_sign.phps

47 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

2016-05-01 13:09:24 +02:00
<?php
2016-05-01 13:09:24 +02:00
/**
* This example shows sending a DKIM-signed message with PHPMailer.
* More info about DKIM can be found here: https://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:
* @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();
2016-05-01 13:09:24 +02:00
$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;
//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;
//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()) {
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
}