skip to Main Content

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


  1. Chosen as BEST ANSWER

    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.


  2. Quoted from Google Help Center:

    Starting November 2022, new senders who send email to personal Gmail
    accounts must set up either SPF or DKIM. Google performs random
    checks on new sender messages to personal Gmail accounts to verify
    they’re authenticated. Messages without at least one of these
    authentication methods will be rejected or marked as spam. This
    requirement doesn’t apply to you if you’re an existing sender.
    However, we recommend you always set up SPF and DKIM to protect your
    organization’s email and to support future authentication
    requirements.

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search