From 70512264872bf9671d8f111fd0653aabf60c4d5b Mon Sep 17 00:00:00 2001 From: hazzeldorn Date: Thu, 18 Jul 2024 18:53:18 +0200 Subject: [PATCH] bugfix: some spam filters blocked emails because of empty reply-to fields --- src/HazzelForms/HazzelForm.php | 12 ++++++------ src/HazzelForms/LegacyMailer.php | 10 +++------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/HazzelForms/HazzelForm.php b/src/HazzelForms/HazzelForm.php index ffabb43..5579b76 100644 --- a/src/HazzelForms/HazzelForm.php +++ b/src/HazzelForms/HazzelForm.php @@ -437,16 +437,16 @@ private function setToken() { * @throws Exception */ public function sendMail($to, $from, $replyTo = '', $senderName = 'HazzelForms', $subject = 'New HazzelForms Message', $template = 'basic') { - if (empty($replyTo)) { - $replyTo = $from; - } if ($this->mailer != null) { // use PHPMailer instance and override default settings - $this->mailer->isHTML(true); - $this->mailer->addAddress($to); $this->mailer->setFrom($from, $senderName); - $this->mailer->addReplyTo($replyTo); + $this->mailer->addAddress($to); + if(!empty($replyTo)){ + $this->mailer->addReplyTo($replyTo); + } + + $this->mailer->isHTML(true); $this->mailer->CharSet = 'UTF-8'; $this->mailer->Subject = $subject; $this->mailer->AltBody = $subject; diff --git a/src/HazzelForms/LegacyMailer.php b/src/HazzelForms/LegacyMailer.php index a828afe..4d8c49e 100644 --- a/src/HazzelForms/LegacyMailer.php +++ b/src/HazzelForms/LegacyMailer.php @@ -8,9 +8,6 @@ class LegacyMailer { protected $to; - protected $from; - protected $replyTo; - protected $senderName; protected $subject; protected $headers = []; protected $message = ''; @@ -23,9 +20,6 @@ class LegacyMailer public function __construct($to, $from, $replyTo, $senderName, $subject, $template, $lang) { $this->to = $to; - $this->from = $from; - $this->replyTo = $replyTo; - $this->senderName = $senderName; $this->subject = $subject; $this->lang = $lang; @@ -38,7 +32,9 @@ public function __construct($to, $from, $replyTo, $senderName, $subject, $templa // define headers $this->headers[] = "From: $senderName" . " <" . $from . ">"; - $this->headers[] = "Reply-To: " . $replyTo; + if(!empty($replyTo)){ + $this->headers[] = "Reply-To: " . $replyTo; + } $this->headers[] = "MIME-Version: 1.0"; $this->headers[] = "Content-Type: multipart/mixed; boundary=\"{$this->mimeBoundary}\""; $this->returnPath = "-f" . $from;