我正在使用 phpmailer 向我发送电子邮件,我什至将 DKIM 与我的谷歌应用程序帐户一起使用,甚至文档说:
您可以通过向您的 Gmail 帐户发送带有架构的电子邮件来轻松测试您的标记是否在端到端正常工作。发件人和收件人为同一账号的所有邮件均忽略注册要求,可用于自测。
我试图发送给我,发送到另一个 gmail 帐户,但什么也没有。在这里使用了示例:https ://developers.google.com/gmail/actions/apps-script-tutorial 并且效果很好,尝试在我的代码中使用它,什么也没有。即使 phpmailer 设置为 google server: smtp.gmail.com,使用 localhost 是否有任何限制?
我正在使用这段代码:
<?php
require_once('phpmailer/class.phpmailer.php');
$content =
'
<html>
<head>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"action": {
"@type": "ConfirmAction",
"name": "Approve Expense",
"handler": {
"@type": "HttpActionHandler",
"url": "https://myexpenses.com/approve?expenseId=abc123"
}
},
"description": "Approval request for Johns $10.13 expense for office supplies"
}
</script>
</head>
<body>
<p>
This a test for a Go-To action in Gmail.
</p>
</body>
</html>
';
echo mailer("mymail","mymail","My Name","test action", $content);
function mailer($to, $from, $from_name, $subject, $body) {
$mail = new PHPMailer(); // create a new object
//$mail->CharSet = "UTF-8";
$mail->IsSMTP(); // enable SMTP
$mail->SMTPAuth = true; // authentication enabled
$mail->Host = 'smtp.gmail.com';
$mail->Username = 'mymail';
$mail->Password = 'pass';
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->isHTML(true);
$mail->SMTPSecure = 'tls';
$mail->AddAddress($to);
if(!$mail->Send()) {
return $mail->ErrorInfo;
} else {
return true;
}
}