I'm using sendgrid to send a verification email to users that create a new account, when testing this by sending the email to myself it ends up in the spam folder with the message "The sender hasn't authenticated this message". How can I fix this? I use the cURL method.
code:
$token = $this->token;
$username = htmlspecialchars($this->username);
// send an email to the user
$email = new \SendGrid\Mail\Mail();
$email->setFrom("[email protected]", "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";
}
You cannot fix it in the client. The issue is with how the account is set up on SendGrid. If you don't have admin access to the sendgrid account yourself, you'll need to find somebody that does.
Once logged into the sendgrid account as an account admin, open up "Settings" in the left nav panel, then select "Sender Authentication":
From there you can authenticate the source domain (using SPF and/or DMARC) and/or authenticate individual sending accounts:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With