Authenticate Email VIA SPF
Asked Answered
R

2

9

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->isSMTP();
$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 = '
<html>
    <head>
        <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"
                }
        }
        </script>
    </head>
    <body>
    <p>
        This a test for a Go-To action in Gmail.
    </p>
    </body>
</html>
';

$mail->msgHTML($html);
$mail->send();

Here is my spf record:

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

Rhona answered 7/3, 2018 at 12:13 Comment(3)
SPF is only domain anti-spoofing mechanism. Have you tried adding DKIM record to your DNS?Wyrick
My goal is to use SPF only. My understanding was it was enough.Rhona
You can't stop spoofing with just SPF. With hardfail in spf most you can do is send it to spam. If you want to stop it from spamming then only way is to use all SPF, DKIM and specially DMARC with policy reject.Blend
A
0

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

include:_spf.google.com
Aplite answered 13/3, 2018 at 19:5 Comment(1)
This is how my SPF records looks like now: v=spf1 a mx include:mailgun.org include:mydomain.com include:_spf.google.com ~all Just tried to send another email and the result is the same.Rhona
T
0

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.

Tithing answered 20/3, 2018 at 12:32 Comment(2)
I added the domain public address, now my record looks like v=spf1 a mx include:xx.xx.xx.xx include:mailgun.org include:domain.com include:_spf.google.com ~all . I tried to send another email and it is still not authenticated.Rhona
To reference an IP address replace include:xx.xx.xx.xx with ip4:xx.xx.xx.xxVanderpool

© 2022 - 2024 — McMap. All rights reserved.