I have a registration form and upon completion it sends an email validation. Problem is that it works for Outlook and for Yahoo, but it is not working for Gmail. I have been tweaking headers trying to resolve the issue. I have even found another post here that is exactly my problem PHP mail() works for Yahoo but not for Gmail
I tried what they said in the answers and my mail still will not send to Gmail. I was going to post a comment in that question but it was 6 years old. Here are two of the methods I’m using. One is the default headers and one is to send them mail:
public function sendActivationEmail() : bool {
return mail($this->to,$this->subject,$this->getMessage(),$this->getHeaders());
}
protected function getDefaultHeaders() : string {
// To send HTML mail, the Content-type header must be set
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-Type: text/html; charset=iso-8859-1rn";
$headers .= "From: [email protected]";
$headers .= "Reply-To: [email protected]";
$headers .= "Cc: Client Tracker New User <[email protected]>rn";
$headers .= "X-Sender: Client Tracker <[email protected]>rn";
$headers .= 'X-Mailer: PHP/' . phpversion()."rn";
$headers .= "X-Priority: 1n"; // Urgent message!
$headers .= "Return-Path: [email protected]"; // Return path for errors
return $headers;
}
I’m at my wits end with this. I am not going to get a dedicated mail server and I do not know how to do any of the SMTP stuff. I did contact my hosting server and they made some changes to the SPF but that only made it so the mail went to yahoo and outlook, but not gmail.
2
Answers
The problem was on my hosting server. They had to identify that my domain and ip was permited. Now in the header information of the emails the SPF=Pass and the DKIM=Pass. So now all the emails are going through.
Quoted from Google Help Center:
So it is necessary to set up SPF or DKIM (or both). SPF can set up by adding TXT record in the DNS as explained in Define your SPF record. DKIM, needs to be set up in your mail server, so if you have a mail provider that does not yet support DKIM, SPF is the only solution.