Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The sender hasn't authenticated this message" using sendgrid

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";
        }
like image 968
Tibo Mertens Avatar asked Sep 12 '25 08:09

Tibo Mertens


1 Answers

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":

enter image description here

From there you can authenticate the source domain (using SPF and/or DMARC) and/or authenticate individual sending accounts:

enter image description here

like image 52
Aleks G Avatar answered Sep 14 '25 23:09

Aleks G