bormat
bormat

Reputation: 1379

Remove gmail warning email not verified when sending mail with PHP

Good morning, I want to remove the gmail warning 'gmail couln't verify that ...@... sent this message' when I send email with php.

I know it is because I use the email function php that don't have authentification so I try PHPMailer and PHP pear but the page turn and turn until the infinite and nothing is happened. My host is 1&1. I try with gmail instead smtp and account instead of 1&1 but same result.

<?php
    // Pear Mail Library
    require_once "Mail.php";
    $from = '<***@motelavigna.co>'; //change this to your email address
    $to = '<***@gmail.com>'; // change to address
    $subject = 'Insert subject here'; // subject of mail
    $body = "Hello world! this is the content of the email"; //content of mail

    $headers = array(
        'From' => $from,
        'To' => $to,
        'Subject' => $subject
    );

    $smtp = Mail::factory('smtp', array(
            'host' => 'auth.smtp.1and1.fr',
            'port' => '465',
            'auth' => true,
            'username' => '***@***.co', //co is not an error
            'password' => '***' // your password
        ));

    // Send the mail
    $mail = $smtp->send($to, $headers, $body);
?>

thanks.

Upvotes: 6

Views: 3388

Answers (1)

Nev
Nev

Reputation: 1568

I came across this issue recently too and realised the problem is not from the PHP script, as I first thought, but from not having an SPF record for the domain name.

An SPF record identifies which mail servers are permitted to send emails from a particular domain name. If the domain doesn't have an SPF record then Gmail can't verify that the email came from the right place.

Coincidentally I'm also with 1&1, so see here for how to set up SPF records for 1&1. The value you need to use is:

v=spf1 include:_spf.perfora.net include:_spf.kundenserver.de -all

You can also check if the email passed the SPF test by clicking the arrow at the top of the email in Gmail, and pressing 'Show original'.

enter image description here

Upvotes: 7

Related Questions