简体   繁体   中英

Sending Email using PHP, not being received by Gmail?

I am trying to send an email using PHP from a free hosting account on Hostinger (hostinger.co.uk).

Here is my code:

<?php 
if(isset($_POST['submit'])){

$to      = 'xxxxxxxxx@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: customer@novel.com' . "\r\n" .
    'Reply-To: customer@novel.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

    }
?>

For some reason when i send the email, it doesn't come through to my gmail account. It's not even in spam.

I reckon this has something to do with the headers and more specifically my from address - since if i change the from email address to the below, then i receive the email.

$headers = 'From: blux@g.com' . "\r\n" .
    'Reply-To: blux@g.com' . "\r\n" .

Please can someone show me / tell me what i am doing wrong here and why gmail doesn't like the other from address?

Thanks in advance

Gmail checks if sender is authorized to send mail or not for security reasons. Due to that if you use any email id whose owner has enabled SPF and DKIM it will reject mail. So try using your server name after @ in your from address. You can set reply-to address to any address you like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM