我正在使用 sendgrid 向创建新帐户的用户发送验证电子邮件,当通过向自己发送电子邮件来测试这一点时,它最终会出现在垃圾邮件文件夹中,并显示消息“发件人尚未验证此消息” 。我怎样才能解决这个问题?我使用 cURL 方法。
代码:
$token = $this->token;
$username = htmlspecialchars($this->username);
// send an email to the user
$email = new \SendGrid\Mail\Mail();
$email->setFrom("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f5869a98909a9b90b5908d9498859990db969a98" rel="noreferrer noopener nofollow">[email protected]</a>", "John Doe");
$email->setSubject("Verifictation email");
$email->addTo($this->email, $this->username);
$email->addContent("text/plain", "Hi $username! Please activate your email. Here is the activation link http://localhost/php/eindwerk/verification.php?token=$token");
$email->addContent(
"text/html", "Hi $username! Please activate your email. <strong>Here is the activation link:</strong> http://localhost/php/eindwerk/verification.php?token=$token"
);
$sendgrid = new \SendGrid(getenv('SENDGRID_API_KEY'));
try {
$response = $sendgrid->send($email);
} catch (Exception $e) {
echo 'Caught exception: '. $e->getMessage() ."\n";
}
最佳答案
您无法在客户端中修复它。问题在于如何在 SendGrid 上设置帐户。如果您自己没有 sendgrid 帐户的管理员访问权限,则需要找到具有该权限的人。
以帐户管理员身份登录 sendgrid 帐户后,在左侧导航面板中打开“设置”,然后选择“发件人身份验证”:
从那里您可以验证源域(使用 SPF 和/或 DMARC)和/或验证各个发送帐户:
关于php - "The sender hasn' t 已使用 sendgrid 验证此消息”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75918564/