From 904c78302c1a37ba72180bfba0a43ca95700e0c4 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Thu, 20 Jun 2024 13:18:55 +0000 Subject: [PATCH] refactor: Make 'From name' customizable --- .../sys/DBMaintenance/version_updates/24.07.00.php | 1 + code/web/sys/Email/SMTPSetting.php | 12 ++++++++++-- install/aspen.sql | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/code/web/sys/DBMaintenance/version_updates/24.07.00.php b/code/web/sys/DBMaintenance/version_updates/24.07.00.php index ad9bbd9cbb..de647a7568 100644 --- a/code/web/sys/DBMaintenance/version_updates/24.07.00.php +++ b/code/web/sys/DBMaintenance/version_updates/24.07.00.php @@ -34,6 +34,7 @@ function getUpdates24_07_00(): array { port int(11) NOT NULL DEFAULT 25, ssl_mode enum('disabled','ssl','tls') NOT NULL, from_address varchar(80) DEFAULT NULL, + from_name varchar(80) DEFAULT NULL, user_name varchar(80) DEFAULT NULL, password varchar(80) DEFAULT NULL, PRIMARY KEY (`id`) diff --git a/code/web/sys/Email/SMTPSetting.php b/code/web/sys/Email/SMTPSetting.php index ab166a9b78..ec9c34583a 100644 --- a/code/web/sys/Email/SMTPSetting.php +++ b/code/web/sys/Email/SMTPSetting.php @@ -12,6 +12,7 @@ class SMTPSetting extends DataObject { public $port; public $ssl_mode; public $from_address; + public $from_name; public $user_name; public $password; @@ -60,11 +61,18 @@ public static function getObjectStructure($context = ''): array { 'from_address' => [ 'property' => 'from_address', 'type' => 'text', - 'label' => 'From', + 'label' => '\'From\' address', 'description' => 'The \'From:\' e-mail address', 'default' => '', 'required' => true, ], + 'from_name' => [ + 'property' => 'from_name', + 'type' => 'text', + 'label' => '\'From\' name', + 'description' => 'The \'From:\' name', + 'required' => true, + ], 'user_name' => [ 'property' => 'user_name', 'type' => 'text', @@ -103,7 +111,7 @@ function sendEmail($to, $replyTo, $subject, $body, $htmlBody, $attachments){ } $mail->From = $this->from_address; - $mail->FromName = 'Aspen Discovery'; + $mail->FromName = $this->from_name; $mail->addAddress($to); for($i = 0; $i < sizeof($attachments['name']); $i++){ diff --git a/install/aspen.sql b/install/aspen.sql index b96acb6881..8b55e2caa0 100644 --- a/install/aspen.sql +++ b/install/aspen.sql @@ -4689,6 +4689,7 @@ CREATE TABLE `smtp_settings` ( `port` int(11) NOT NULL DEFAULT 25, `ssl_mode` enum('disabled','ssl','tls') NOT NULL, `from_address` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, + `from_name` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, `user_name` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, `password` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, PRIMARY KEY (`id`)