From e2178de1f9133b794a9e88bde5f611d6978543b1 Mon Sep 17 00:00:00 2001 From: "Emanuele \"ToX\" Toscano" Date: Tue, 21 Mar 2023 18:46:14 +0100 Subject: [PATCH] Modifiche all'invio delle email: mittente e reply_to --- config.example.php | 9 ++++++ mail.php | 38 +++++++++++++++++++++---- src/Notifications/EmailNotification.php | 16 +++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/config.example.php b/config.example.php index ae73cb833..cb5c06f6f 100755 --- a/config.example.php +++ b/config.example.php @@ -65,3 +65,12 @@ 'print' => [], 'js' => [], ]; + +// Indica se i messaggi di posta elettronica devono essere inviati con +// l'istruzione reply_to impostata con l'indirizzo email dell'utente collegato +$force_reply_to_sender = false; + +// Indica se i messaggi di posta elettronica devono essere inviati con l'account di posta elettronica +// corrispondente all'indirizzo email dell'utente collegato. Se non c'è un account con questo indirizzo +// email, verrà utilizzato l'account di default. +$force_mail_from_sender = false; diff --git a/mail.php b/mail.php index ff73c28fb..dc9d912ca 100755 --- a/mail.php +++ b/mail.php @@ -35,7 +35,7 @@ $emails = []; if ($module->replacePlaceholders($id_record, '{email}')) { $emails = explode(';', $module->replacePlaceholders($id_record, '{email}', $placeholder_options)); -} +} $id_anagrafica = $module->replacePlaceholders($id_record, '{id_anagrafica}', $placeholder_options); @@ -58,7 +58,7 @@ $anagrafica = $dbo->table('an_anagrafiche')->where('idanagrafica', $tecnico['id_tecnico'])->where('email', '!=', '')->first(); if (!in_array($anagrafica->email, $emails)) { $emails[] = $anagrafica->email; - } + } } } @@ -94,9 +94,37 @@ - + '; + +$from_name = $smtp['from_name']; +$from_address = $smtp['from_address']; +$reply_to_address = ''; + +if (!empty($config['force_reply_to_sender']) && $config['force_reply_to_sender'] === true) { + $user = \Auth::user(); + $from_name = $user->username; + $from_address = $smtp['from_address']; + $reply_to_address = $user->email; +} + +if (isset($config['force_mail_from_sender']) && $config['force_mail_from_sender'] === true) { + $user = \Auth::user(); + $email = $user->email; + $reply_to_address = ''; + $account = Modules\Emails\Account::where('username', $email)->first(); + if (!empty($account)) { + $from_name = $account->from_name; + $from_address = $account->from_address; + $reply_to_address = ''; + } +} -

'.tr('Mittente').': '.$smtp['from_name'].' <'.$smtp['from_address'].'>

'; +echo '

' . tr('Mittente') . ': '; +echo $from_name . ' <' . $from_address . '>

'; +if ($reply_to_address !== '') { + echo '

' . tr('Indirizzo per le risposte') . ': '; + echo ' <' . $reply_to_address . '>

'; +} if (!empty($template['cc'])) { echo ' @@ -180,7 +208,7 @@ 'id' => 'body_'.rand(0, 999), 'value' => $body, ]); - + echo' '; diff --git a/src/Notifications/EmailNotification.php b/src/Notifications/EmailNotification.php index bcfb07ff1..6a78ab3ff 100755 --- a/src/Notifications/EmailNotification.php +++ b/src/Notifications/EmailNotification.php @@ -40,6 +40,7 @@ public function __construct($account = null, $exceptions = null) parent::__construct($exceptions); $this->CharSet = 'UTF-8'; + $config = \App::getConfig(); // Configurazione di base $account = $account instanceof Account ? $account : Account::find($account); @@ -47,6 +48,21 @@ public function __construct($account = null, $exceptions = null) $account = Account::where('predefined', true)->first(); } + if (isset($config['force_reply_to_sender']) && $config['force_reply_to_sender'] === true) { + $user = \Auth::user(); + $account['from_name'] = $user->username; + $this->AddReplyTo($user->email, $user->nome); + } + + if (isset($config['force_mail_from_sender']) && $config['force_mail_from_sender'] === true) { + $user = \Auth::user(); + $email = $user->email; + $account_data = Account::where('username', $email)->first(); + if (!empty($account_data)) { + $account = $account_data; + } + } + // Preparazione email $this->IsHTML(true);