PHPMailer Can't send E-Mails to gmail

Viewed 46

I couldn't send mails to gmail accounts. Sending mails to other providers works. The mail also does not end up in the spam folder and there is no response to the sender address. I also register the domains f in the Google Postmaster Tool to verify the Domain. Could the problem be that the script is running on a different server than the email domain? On this case, the script is just running on my local machine for development.

When I send Mails from the E-Mail Servers Webinterface, it works.

This is the header when I send the Email to GMX:

Return-Path: <info@rescueoffice.de>
Authentication-Results: gmx.net; dkim=none
Received: from dd38416.kasserver.com ([85.13.128.172]) by mx-ha.gmx.net (mxgmx101 [212.227.17.5]) with ESMTPS (Nemesis) id 1MmlP4-1pF3po3RYM-00joqF for <julia_reeh@gmx.de>; Thu, 08 Sep 2022 23:50:14 +0200
Received: from localhost (unknown [85.233.52.241]) by dd38416.kasserver.com (Postfix) with ESMTPSA id 33A4F44405D5 for <julia_reeh@gmx.de>; Thu, 8 Sep 2022 23:50:14 +0200 (CEST)
Date: Thu, 8 Sep 2022 21:50:13 +0000
To: Markus Bodmann <julia_reeh@gmx.de>
From: Intranet Rettungsdienst LK Harburg <info@rescueoffice.de>
Subject: =?UTF-8?Q?Logindaten_f=C3=BCr_Markus_Bodmann?=
Message-ID: <uUg4R9CgLINIj7xxWDaGHDxutEMuF1YIKKrJ0@localhost>
X-Mailer: PHPMailer 6.6.0 (https://github.com/PHPMailer/PHPMailer)
MIME-Version: 1.0
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
Envelope-To: <julia_reeh@gmx.de>
X-GMX-Antispam: 0 (Mail was not recognized as spam); Detail=V3;
X-Spam-Flag: NO

EDIT

function sendMail(string $from, string $to, string $toName, string $subject, string $body): bool
{
    $mail = new PHPMailer(true);
    $mail->CharSet = 'UTF-8';

    try {
        //Server settings
        $mail->isSMTP();
        $mail->Host         = MAIL_HOST;
        $mail->SMTPAuth     = true;
        $mail->Username     = MAIL_USER;
        $mail->Password     = MAIL_PASSWORD;
        $mail->SMTPSecure   = PHPMailer::ENCRYPTION_SMTPS;
        $mail->Port         = MAIL_PORT;

        //Recipients
        $mail->setFrom(MAIL_SENDER, $from);
        $mail->addAddress($to, $toName);

        //Content
        $mail->isHTML(true);
        $mail->Subject = $subject;
        $mail->Body    = $body;

        $mail->send();

        return true;

    } catch (Exception $e) {
        return false;
    }
}
1 Answers

The thing that jumps out at me is that Reply-To is missing.

You may already have looked at it. But for completeness, you should look at this document Prevent emails to Gmail users from being blocked or sent to spam

There are various sites that will check your email for spam score. You should try them. I tried the headers you have on one of them. The results are not fully valid as I didn't have the full email. But it did not like the Date header. I found a few years ago that bigpond was very fussy about the date header. Another ISP wanted the User-Agent header.

Related