我正在使用phpmailer通过SMTP发送电子邮件,它经过postfix发送。当我从我的邮箱发送电子邮件时,使用DKIM和DMARC没有问题,但是当我使用phpmailer发送电子邮件时,无法获得DKIM。
<?php
function send_email($to, $from_email, $from_name, $subject, $body,
$is_html=false, $attachments=null) {
global $smtp_host, $smtp_port, $smtp_user, $smtp_password;
try {
$email = new PHPMailer(true);
if ($from_email === $smtp_user) {
$email->isSMTP();
$email->Host = $smtp_host;
$email->Port = $smtp_port;
$email->SMTPAuth = true;
$email->Username = $smtp_user;
$email->Password = $smtp_password;
$email->SMTPSecure = 'tls';
}
$email->CharSet = 'UTF-8';
$email->From = $from_email;
$email->FromName = $from_email;
$email->Subject = $subject;
$email->Body = $body;
$email->AddAddress($to);
if ($is_html == true) {
$email->IsHTML(true);
$email->Encoding = 'base64';
}
if ($attachments != null) {
foreach ($attachments as $attachment) {
$apath = $attachment["path"];
$aname = $attachment["name"];
$email->AddAttachment($apath , $aname);
}
}
$email->Send();
$status = "success";
}
catch (phpmailerException $e) {
$status = $e->errorMessage();
}
catch (Exception $e) {
$status = $e->getMessage();
}
return $status;
}
我认为我需要将这个代码添加到我的代码中,但我不确定是否必须添加此代码。我以为opendkim会自动将DKIM添加到邮件头部,但实际上并没有。
$email->DKIM_domain = 'mydomain.com';
$email->DKIM_private = '/path/to/private_key';
$email->DKIM_selector = 'default';
$email->DKIM_passphrase = '1234567';