Home » Php » php – Authenticate Email VIA SPF

php – Authenticate Email VIA SPF

Posted by: admin July 12, 2020 Leave a comment


Okay, I cant figure this out. I am using PHPMailer to send an email from my domain – example.com to myself. I am sending the email to myself.(testing the google schema markup), but the emails are not authenticated.
Here is the code I use to send the email to myself.

$mail = new PHPMailer();
$mail->SMTPDebug = 2;
$mail->Host = 'tls://smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';      
$mail->Username = '[email protected]';
$mail->Password = '';
$mail->setFrom('[email protected]');
$mail->addAddress('[email protected]');

$mail->Subject = 'Microdata Test';
$html = '
        <script type="application/ld+json">
            "@context":       "http://schema.org",
            "@type":          "EmailMessage",
            "description":    "Check this out",
            "potentialAction": {
                "@type": "ViewAction",
                "target":   "https://www.youtube.com/watch?v=eH8KwfdkSqU"
        This a test for a Go-To action in Gmail.


Here is my spf record:

v=spf1 a mx include:mailgun.org include:mydomain.com ~all

How to&Answers:

Since you are sending the email with Google’s smtp, you have to include it in your SPF:



You are sending from your host to google over SMTP. This means that Google will see if you host is in your SPF record and act accordingly

So, you have to include your public ip in the SPF record and pray that this is enough.

Also, your username is myemail not [email protected]. And password should be the real password, of course.

If nothing works, consult PHPMailer logs, there should be more hints.