Php sent emails getting blocked in gmail

kikloo

Verified User
Joined
Jul 17, 2019
Messages
73
Hi,

I am noticing that emails that go out via php scripts are being blocked by gmail where as if I send email manually from webmail etc to same gmail then it goes through ok.

Why that would be happening ?

Any suggestions would be highly helpful.

Thanks in advance.
 
Because they are probably missing DKIM,SPF /DMARC. (email is send from the server host name like server.domai.com)
you can setup DKIM DMARC and SPF for your hostname.
If its to much work let your mails send by autenticated mail plugins (if you are using CMS systems like Wordpress)
 
Last edited:
You only need SPF for Gmail, but DKIM is better, DMARC can be best but can also cause forward issues.

You probably don't have a seperate DNS entry for your hostname. If you create one, the SPF record will be added automatically, and you're ready to mail to gmail via PHP.
After that, also create an SSL certificate for your hostname.
 
Thanks for the info, you maybe correct that I don’t have spf or dkim for hostname. Can you please tell me how I can set that up for the hostname ? I already have a ssl for the hostname.
 
Do you have a seperate DNS entry for the hostname?
If yes add a TXT record.
server.domain.com. 3600 IN TXT "v=spf1 a mx ip4:192.168.0.1 ip6:2a02:cxxx:xxx:xxx:0:0:0:1 ~all"
replace server.domain.com and with the correct hostname and the same for the ip's. If you do not use ipv6, just remove the ip6 part.
 
Hi,

I checked and I already have spf / dkim for the hostname. I sent a test email on mail-tester and it gave 7.7/10 score. A 2.499 score was reduced because the mail was sent using a php script. Please check the attached screenshot.

How to better it ?

Thanks
 

Attachments

  • mailtest.png
    mailtest.png
    109.8 KB · Views: 359
The score is good.

Do you also have an FQDN hostname and a correct rDNS/PTR record to that hostname?
Do you use ipv6?

Check your logs and post the exact error notice you get from Gmail.
 
Hi,

Yes I have fqdn hostname and correct rdns/ptr is set to the hostname.

I am on hetzner so yes I have ipv6 but I don’t use it.

Thanks.
 
If ipv6 is present on the server it might be automatically used by Exim.
An rDNS/PTR record for the ipv6 address is required in that case too. That is also possible at Hetzner, we got servers there too.

However, if everything is correct, then we need more info like the real domain name where the hostname is from, so we can do some investigation as to where the problem could be.
If you don't want to place it in public you can send me a pm too, but since I'm a bit busy, I can't guarantee an answer today, but it might.
 
Thank you for the quickly reply. I appericiate your help. I will PM you.

Thanks.
 
Thank you.
I've little time at the moment but I did a quick check for you.
The ipv4 rDNS/PTR record is indeed correct.

Now I'm wondering if you are also receiving mails at that domain, because no MX record is present for your main domain you gave me.
Next to that, there also is no A record voor the www for your domain present.
Also there is no SPF record present for your main domain. So if your domain is server.domain.com then server.domain.com has SPF but domain.com has not.

I would fix those first.
Most likely fixing the MX record and SPF for main domain would fix the gmail issue as Gmail also checks MX records, and now there are none existing.
 
Hi,

Thanks for checking it out. The domain is pointing to cloudflare and there I have specified the hostname, spf etc. I don’t have any hosted site for the domain.com as it’s just meant for dns purposes only I.e hostname, name servers etc.

The sites of which the emails are going into spam in gmail only when sending via php scripts are client sites hosted on the server.

Hope that gives some clarity.

Thanks.
 
Hello.

You're welcome. I presume these client sides do have correct SPF records. If the screenshot of mailtester is from mail of one of those clients then it's correct.

Can you post me the exact log result when sending via php to gmail, either here or per pm?
 
Where can I get the log ? It seems that mails sent by WHMCS are also not reaching the gmail email accounts.
 
If it's php scripts, try the /home/user/.php/php-mail.log file.
For authenticated mail try /var/log/exim/mainlog file.
 
Back
Top