From 21b9677f3d9eb48bf53f9130984d2c6922a58a32 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Mon, 12 Jan 2026 16:16:41 +0100 Subject: [PATCH] custom preorder notifications: handling empty emailaddress and sending errors --- scripts/preorder/custom_notifications/init.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/preorder/custom_notifications/init.php b/scripts/preorder/custom_notifications/init.php index a040370a6..2d1eb03ed 100644 --- a/scripts/preorder/custom_notifications/init.php +++ b/scripts/preorder/custom_notifications/init.php @@ -56,6 +56,9 @@ function sendPreorderEmail($mailtemplate, $preordercampaign, $preorder, $email_t } } + $email_to = trim($preorder->email); + if(!$email_to) return false; + $subject = $mailtemplate->getVariableReplacedSubject($replacers); $body = ''; $body .= $mailtemplate->renderBody($replacers); @@ -71,7 +74,7 @@ function sendPreorderEmail($mailtemplate, $preordercampaign, $preorder, $email_t $email->setBody($body); } $email->setFrom($preordercampaign->from_email, $preordercampaign->from_email_name); - $email->setTo($preorder->email); + $email->setTo($email_to); $email->setHeader("X-".ucfirst(MFAPPNAME)."-pid", $preorder->id); $email->setHeader("X-".ucfirst(MFAPPNAME)."-ps", '300-custom'); // add attachments @@ -81,12 +84,15 @@ function sendPreorderEmail($mailtemplate, $preordercampaign, $preorder, $email_t logMessage("Adding attachment: " . $file->filename); $email->addAttachment($file->file->getFullPath(), null, $file->filename, $file->file->mimetype ?: null); } - $email->send(); + if(!$email->send()) { + logMessage("Error sending email for Preorder ID {$preorder->id}"); + return false; + } logMessage("Email sent successfully for Preorder ID: $preorder->id, Campaign: $preordercampaign->name, Type: $email_type"); $psn_log = PreorderStatusnotificationLog::create([ "preorder_id" => $preorder->id, "email_type" => $email_type, - "email" => $preorder->email, + "email" => $email_to, ]); $psn_log->save(); } catch (Exception $e) {