public function PHPMailer::DKIM_Add in SMTP Authentication Support 7
Same name and namespace in other branches
- 7.2 smtp.phpmailer.inc \PHPMailer::DKIM_Add()
Create the DKIM header, body, as new header
@access public
Parameters
string $headers_line Header lines:
string $subject Subject:
string $body Body:
1 call to PHPMailer::DKIM_Add()
- PHPMailer::Send in ./
smtp.phpmailer.inc - Creates message and assigns Mailer. If the message is not sent successfully then it returns FALSE. Use the ErrorInfo variable to view description of the error.
File
- ./
smtp.phpmailer.inc, line 2282 - The mail handler class in smtp module, based on code of the phpmailer library, customized and relicensed to GPLv2.
Class
- PHPMailer
- PHPMailer - PHP email transport class NOTE: Requires PHP version 5 or later @package PHPMailer @author Andy Prevost @author Marcus Bointon @copyright 2004 - 2009 Andy Prevost
Code
public function DKIM_Add($headers_line, $subject, $body) {
$DKIMsignatureType = 'rsa-sha1';
// Signature & hash algorithms
$DKIMcanonicalization = 'relaxed/simple';
// Canonicalization of header/body
$DKIMquery = 'dns/txt';
// Query method
$DKIMtime = REQUEST_TIME;
// Signature Timestamp = seconds since 00:00:00 - Jan 1, 1970 (UTC time zone)
$subject_header = "Subject: {$subject}";
$headers = explode("\r\n", $headers_line);
foreach ($headers as $header) {
if (strpos($header, 'From:') === 0) {
$from_header = $header;
}
elseif (strpos($header, 'To:') === 0) {
$to_header = $header;
}
}
$from = str_replace('|', '=7C', $this
->DKIM_QP($from_header));
$to = str_replace('|', '=7C', $this
->DKIM_QP($to_header));
$subject = str_replace('|', '=7C', $this
->DKIM_QP($subject_header));
// Copied header fields (dkim-quoted-printable
$body = $this
->DKIM_BodyC($body);
$DKIMlen = strlen($body);
// Length of body
$DKIMb64 = base64_encode(pack("H*", sha1($body)));
// Base64 of packed binary SHA-1 hash of body
$ident = $this->DKIM_identity == '' ? '' : " i=" . $this->DKIM_identity . ";";
$dkimhdrs = "DKIM-Signature: v=1; a=" . $DKIMsignatureType . "; q=" . $DKIMquery . "; l=" . $DKIMlen . "; s=" . $this->DKIM_selector . ";\r\n" . "\tt=" . $DKIMtime . "; c=" . $DKIMcanonicalization . ";\r\n" . "\th=From:To:Subject;\r\n" . "\td=" . $this->DKIM_domain . ";" . $ident . "\r\n" . "\tz={$from}\r\n" . "\t|{$to}\r\n" . "\t|{$subject};\r\n" . "\tbh=" . $DKIMb64 . ";\r\n" . "\tb=";
$toSign = $this
->DKIM_HeaderC($from_header . "\r\n" . $to_header . "\r\n" . $subject_header . "\r\n" . $dkimhdrs);
$signed = $this
->DKIM_Sign($toSign);
return "X-PHPMAILER-DKIM: phpmailer.worxware.com\r\n" . $dkimhdrs . $signed . "\r\n";
}