From 5e3e63fe2bd830675742459db4e0c7bdddb3fd10 Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Sat, 13 Aug 2022 11:12:09 +0200 Subject: [PATCH 01/14] Added more placeholder to email wrapper, changed the way of how to send emails --- adm_program/system/classes/Email.php | 174 ++++++++++++++++++--------- 1 file changed, 117 insertions(+), 57 deletions(-) diff --git a/adm_program/system/classes/Email.php b/adm_program/system/classes/Email.php index 3a65bd60c6..e9bbdfe38b 100644 --- a/adm_program/system/classes/Email.php +++ b/adm_program/system/classes/Email.php @@ -150,18 +150,22 @@ public function __construct() * in the email send process. * @param string $address A valid email address to which the email should be sent. * @param string $name The name of the recipient that will be shown in the email header. + * @param array $additionalFields Additional fields to map in a Key Value like Array. Not used at all yet. * @return bool Returns **true** if the address was added to the recipients list. */ - public function addRecipient($address, $name = '') + public function addRecipient($address, $firstName = '', $name = '', $additionalFields = array()) { // Recipients must be Ascii-US formatted, so encode in MimeHeader - $asciiName = stripslashes($name); + $asciiName = stripslashes($firstName . ' ' . $name); // check if valid email address and if email not in the recipients array if (StringUtils::strValidCharacters($address, 'email') && array_search($address, array_column($this->emRecipientsArray, 'address')) === false) { - $this->emRecipientsArray[] = array('name' => $asciiName, 'address' => $address); - $this->emRecipientsNames[] = $name; + $recipient = array('name' => $asciiName, 'address' => $address, 'firstname' => $firstName, 'surname' => $name); + $recipient = array_merge($recipient , $additionalFields); + $this->emRecipientsArray[] = $recipient; + $this->emRecipientsNames[] = $firstName . ' ' . $name; + return true; } return false; @@ -252,7 +256,7 @@ public function addRecipientsByRole($roleUuid, $memberStatus = self::EMAIL_ONLY_ // all email addresses will be attached as BCC while ($row = $statement->fetch()) { if (StringUtils::strValidCharacters($row['email'], 'email')) { - $this->addRecipient($row['email'], $row['firstname'] . ' ' . $row['lastname']); + $this->addRecipient($row['email'], $row['firstname'], $row['lastname']); ++$numberRecipientsAdded; } } @@ -306,7 +310,7 @@ public function addRecipientsByUserId($userId) // all email addresses will be attached as BCC while ($row = $statement->fetch()) { if (StringUtils::strValidCharacters($row['email'], 'email')) { - $this->addRecipient($row['email'], $row['firstname'] . ' ' . $row['lastname']); + $this->addRecipient($row['email'], $row['firstname'], $row['lastname']); ++$numberRecipientsAdded; } } @@ -323,10 +327,10 @@ public function addRecipientsByUserId($userId) * @param string $name * @return true|string */ - public function addCopy($address, $name = '') + public function addCopy($address, $firstName = '', $name = '') { try { - $this->addCC($address, $name); + $this->addCC($address, $firstName .' '. $name); } catch (Exception $e) { return $e->errorMessage(); } catch (\Exception $e) { @@ -346,9 +350,9 @@ public function addCopy($address, $name = '') * @return bool * @deprecated 4.2.0:4.3.0 "addBlindCopy()" is deprecated, use "addRecipient()" instead. */ - public function addBlindCopy($address, $name = '') + public function addBlindCopy($address, $firstName = '', $name = '') { - return $this->addRecipient($address, $name); + return $this->addRecipient($address, $firstName, $name); } /** @@ -565,6 +569,32 @@ public function setTemplateText($text, $senderName, $senderEmail, $senderUuid, $ $this->emHtmlText = $emailHtmlText; } + + /** + * Add the user specific template text to the email message and replace the plaeholders of the template. + * @param string $text Email text that should be send + * @param string $firstname Receiver firstname + * @param string $surname Receiver surname + * @param string $email Receiver email address + * @param string $name Receiver firstname and surname + */ + public function setUserSpecificTemplateText($text, $firstName, $surname, $email, $name) + { + // replace all line feeds within the mailtext into simple breaks because only those are valid within mails + $text = str_replace("\r\n", "\n", $text); + + // replace parameters in email template + $replaces = array( + '#receiver_first_name#' => $firstName, + '#receiver_firstname#' => $firstName, + '#receiver_surname#' => $surname, + '#receiver_lastname#' => $surname, + '#receiver_email#' => $email, + '#receiver_name#' => $name + ); + return StringUtils::strMultiReplace($text, $replaces); + } + /** * Funktion um den Nachrichtentext an die Mail uebergeben * @param string $text @@ -634,66 +664,96 @@ public function sendEmail() { global $gSettingsManager, $gLogger, $gDebug, $gValidLogin, $gCurrentUser; - // add body to the email - if ($this->emSendAsHTML) { - $this->msgHTML($this->emHtmlText); - } else { - $this->Body = $this->emText; - } - try { // if there is a limit of email recipients than split the recipients into smaller packages $recipientsArrays = array_chunk($this->emRecipientsArray, $gSettingsManager->getInt('mail_number_recipients')); foreach ($recipientsArrays as $recipientsArray) { - // if number of bcc recipients = 1 then send the mail directly to the user and not as bcc - if ($this->countRecipients() === 1) { - // remove all current recipients from mail - $this->clearAllRecipients(); - - $this->addAddress($recipientsArray[0]['address'], $recipientsArray[0]['name']); - if ($gDebug) { - $gLogger->notice('Email send as TO to ' . $recipientsArray[0]['name'] . ' (' . $recipientsArray[0]['address'] . ')'); - } - } elseif ($gSettingsManager->getBool('mail_into_to')) { - // remove all current recipients from mail - $this->clearAllRecipients(); + try { + // if number of bcc recipients = 1 then send the mail directly to the user and not as bcc + if ($this->countRecipients() === 1) { + // remove all current recipients from mail + $this->clearAllRecipients(); - // add all recipients as bcc to the mail - foreach ($recipientsArray as $recipientTO) { - $this->addAddress($recipientTO['address'], $recipientTO['name']); + $this->addAddress($recipientsArray[0]['address'], $recipientsArray[0]['name']); if ($gDebug) { - $gLogger->notice('Email send as TO to ' . $recipientTO['name'] . ' (' . $recipientTO['address'] . ')'); + $gLogger->notice('Email send as TO to ' . $recipientsArray[0]['name'] . ' (' . $recipientsArray[0]['address'] . ')'); + } + // add body to the email + if ($this->emSendAsHTML) { + $html = $this->setUserSpecificTemplateText($this->emHtmlText, $recipientsArray[0]['firstname'], $recipientsArray[0]['surname'], $recipientsArray[0]['address'], $recipientsArray[0]['name']); + $this->msgHTML($html); + } else { + $txt = $this->setUserSpecificTemplateText($this->emText, $recipientsArray[0]['firstname'], $recipientsArray[0]['surname'], $recipientsArray[0]['address'], $recipientsArray[0]['name']); + $this->Body = $txt; + } + + // now send mail + $this->send(); + } elseif ($gSettingsManager->getBool('mail_into_to')) { + + // add all recipients as bcc to the mail + foreach ($recipientsArray as $recipientTO) { + // remove all current recipients from mail + $this->clearAllRecipients(); + + $this->addAddress($recipientTO['address'], $recipientTO['name']); + if ($gDebug) { + $gLogger->notice('Email send as TO to ' . $recipientTO['name'] . ' (' . $recipientTO['address'] . ')'); + } + + // add body to the email + if ($this->emSendAsHTML) { + $html = $this->setUserSpecificTemplateText($this->emHtmlText, $recipientTO['firstname'], $recipientTO['surname'], $recipientTO['address'], $recipientTO['name']); + $this->msgHTML($html); + } else { + $txt = $this->setUserSpecificTemplateText($this->emText, $recipientTO['firstname'], $recipientTO['surname'], $recipientTO['address'], $recipientTO['name']); + $this->Body = $txt; + } + + // now send mail + $this->send(); + } + } else { + // normally we need no To-address and set "undisclosed recipients", but if + // that won't work than the following address will be set + if ($gValidLogin && (int) $gSettingsManager->get('mail_recipients_with_roles') === 1) { + // fill recipient with sender address to prevent problems with provider + $this->addAddress($gCurrentUser->getValue('EMAIL'), $gCurrentUser->getValue('FIRST_NAME').' '.$gCurrentUser->getValue('LAST_NAME')); + } elseif ((int) $gSettingsManager->get('mail_recipients_with_roles') === 2 + || (!$gValidLogin && (int) $gSettingsManager->get('mail_recipients_with_roles') === 1)) { + // fill recipient with administrators address to prevent problems with provider + $this->addAddress($gSettingsManager->getString('email_administrator'), $gL10n->get('SYS_ADMINISTRATOR')); } - } - } else { - // remove only all BCC because to-address could be explicit set if undisclosed recipients won't work - $this->clearBCCs(); - - // normally we need no To-address and set "undisclosed recipients", but if - // that won't work than the following address will be set - if ($gValidLogin && (int) $gSettingsManager->get('mail_recipients_with_roles') === 1) { - // fill recipient with sender address to prevent problems with provider - $this->addAddress($gCurrentUser->getValue('EMAIL'), $gCurrentUser->getValue('FIRST_NAME').' '.$gCurrentUser->getValue('LAST_NAME')); - } elseif ((int) $gSettingsManager->get('mail_recipients_with_roles') === 2 - || (!$gValidLogin && (int) $gSettingsManager->get('mail_recipients_with_roles') === 1)) { - // fill recipient with administrators address to prevent problems with provider - $this->addAddress($gSettingsManager->getString('email_administrator'), $gL10n->get('SYS_ADMINISTRATOR')); - } - // add all recipients as bcc to the mail - foreach ($recipientsArray as $recipientBCC) { - $this->addBCC($recipientBCC['address'], $recipientBCC['name']); - if ($gDebug) { - $gLogger->notice('Email send as BCC to ' . $recipientBCC['name'] . ' (' . $recipientBCC['address'] . ')'); + // add all recipients as bcc to the mail + foreach ($recipientsArray as $recipientBCC) { + // remove only all BCC because to-address could be explicit set if undisclosed recipients won't work + $this->clearBCCs(); + $this->addBCC($recipientBCC['address'], $recipientBCC['name']); + if ($gDebug) { + $gLogger->notice('Email send as BCC to ' . $recipientBCC['name'] . ' (' . $recipientBCC['address'] . ')'); + } + + // add body to the email + if ($this->emSendAsHTML) { + $html = $this->setUserSpecificTemplateText($this->emHtmlText, $recipientBCC['firstname'], $recipientBCC['surname'], $recipientBCC['address'], $recipientBCC['name']); + $this->msgHTML($html); + } else { + $txt = $this->setUserSpecificTemplateText($this->emText, $recipientBCC['firstname'], $recipientBCC['surname'], $recipientBCC['address'], $recipientBCC['name']); + $this->Body = $txt; + } + + // now send mail + $this->send(); } } + } catch (Exception $e) { + return $e->errorMessage(); + } catch (\Exception $e) { + return $e->getMessage(); } - - // now send mail - $this->send(); } - // now send the email as a copy to the sender if ($this->emCopyToSender) { $this->sendCopyMail(); From d76dc49fdbd18e44b9b9eaf998fe891e76f38ae8 Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Sun, 14 Aug 2022 21:57:54 +0200 Subject: [PATCH 02/14] Cleanup and removed not needed settings due to this changes. As we send it to each receipient as a single mail we are using the TO Field as receipient and do not need to handle BCC/TO. --- .../modules/preferences/preferences.php | 13 ---- adm_program/system/classes/Email.php | 74 ++----------------- 2 files changed, 8 insertions(+), 79 deletions(-) diff --git a/adm_program/modules/preferences/preferences.php b/adm_program/modules/preferences/preferences.php index 1b32e369b6..64dcf47aad 100644 --- a/adm_program/modules/preferences/preferences.php +++ b/adm_program/modules/preferences/preferences.php @@ -513,19 +513,6 @@ function getPreferencePanel($group, $id, $parentId, $title, $icon, $body) $formValues['mail_sendmail_name'], array('maxLength' => 50, 'helpTextIdInline' => 'SYS_SENDER_NAME_DESC') ); -$selectBoxEntries = array(0 => $gL10n->get('SYS_HIDDEN'), 1 => $gL10n->get('SYS_SENDER'), 2 => $gL10n->get('SYS_ADMINISTRATOR')); -$formEmailDispatch->addSelectBox( - 'mail_recipients_with_roles', - $gL10n->get('SYS_MULTIPLE_RECIPIENTS'), - $selectBoxEntries, - array('defaultValue' => $formValues['mail_recipients_with_roles'], 'showContextDependentFirstEntry' => false, 'helpTextIdInline' => 'SYS_MULTIPLE_RECIPIENTS_DESC') -); -$formEmailDispatch->addCheckbox( - 'mail_into_to', - $gL10n->get('SYS_INTO_TO'), - (bool) $formValues['mail_into_to'], - array('helpTextIdInline' => 'SYS_INTO_TO_DESC') -); $formEmailDispatch->addInput( 'mail_number_recipients', $gL10n->get('SYS_NUMBER_RECIPIENTS'), diff --git a/adm_program/system/classes/Email.php b/adm_program/system/classes/Email.php index e9bbdfe38b..dab6389134 100644 --- a/adm_program/system/classes/Email.php +++ b/adm_program/system/classes/Email.php @@ -662,7 +662,7 @@ private function sendCopyMail() */ public function sendEmail() { - global $gSettingsManager, $gLogger, $gDebug, $gValidLogin, $gCurrentUser; + global $gSettingsManager, $gLogger, $gDebug; try { // if there is a limit of email recipients than split the recipients into smaller packages @@ -670,83 +670,25 @@ public function sendEmail() foreach ($recipientsArrays as $recipientsArray) { try { - // if number of bcc recipients = 1 then send the mail directly to the user and not as bcc - if ($this->countRecipients() === 1) { - // remove all current recipients from mail + // add all recipients as bcc to the mail + foreach ($recipientsArray as $recipient) { $this->clearAllRecipients(); - - $this->addAddress($recipientsArray[0]['address'], $recipientsArray[0]['name']); + $this->addAddress($recipient['address'], $recipient['name']); if ($gDebug) { - $gLogger->notice('Email send as TO to ' . $recipientsArray[0]['name'] . ' (' . $recipientsArray[0]['address'] . ')'); + $gLogger->notice('Email send as TO to ' . $recipient['name'] . ' (' . $recipient['address'] . ')'); } + // add body to the email if ($this->emSendAsHTML) { - $html = $this->setUserSpecificTemplateText($this->emHtmlText, $recipientsArray[0]['firstname'], $recipientsArray[0]['surname'], $recipientsArray[0]['address'], $recipientsArray[0]['name']); + $html = $this->setUserSpecificTemplateText($this->emHtmlText, $recipient['firstname'], $recipient['surname'], $recipient['address'], $recipient['name']); $this->msgHTML($html); } else { - $txt = $this->setUserSpecificTemplateText($this->emText, $recipientsArray[0]['firstname'], $recipientsArray[0]['surname'], $recipientsArray[0]['address'], $recipientsArray[0]['name']); + $txt = $this->setUserSpecificTemplateText($this->emText, $recipient['firstname'], $recipient['surname'], $recipient['address'], $recipient['name']); $this->Body = $txt; } // now send mail $this->send(); - } elseif ($gSettingsManager->getBool('mail_into_to')) { - - // add all recipients as bcc to the mail - foreach ($recipientsArray as $recipientTO) { - // remove all current recipients from mail - $this->clearAllRecipients(); - - $this->addAddress($recipientTO['address'], $recipientTO['name']); - if ($gDebug) { - $gLogger->notice('Email send as TO to ' . $recipientTO['name'] . ' (' . $recipientTO['address'] . ')'); - } - - // add body to the email - if ($this->emSendAsHTML) { - $html = $this->setUserSpecificTemplateText($this->emHtmlText, $recipientTO['firstname'], $recipientTO['surname'], $recipientTO['address'], $recipientTO['name']); - $this->msgHTML($html); - } else { - $txt = $this->setUserSpecificTemplateText($this->emText, $recipientTO['firstname'], $recipientTO['surname'], $recipientTO['address'], $recipientTO['name']); - $this->Body = $txt; - } - - // now send mail - $this->send(); - } - } else { - // normally we need no To-address and set "undisclosed recipients", but if - // that won't work than the following address will be set - if ($gValidLogin && (int) $gSettingsManager->get('mail_recipients_with_roles') === 1) { - // fill recipient with sender address to prevent problems with provider - $this->addAddress($gCurrentUser->getValue('EMAIL'), $gCurrentUser->getValue('FIRST_NAME').' '.$gCurrentUser->getValue('LAST_NAME')); - } elseif ((int) $gSettingsManager->get('mail_recipients_with_roles') === 2 - || (!$gValidLogin && (int) $gSettingsManager->get('mail_recipients_with_roles') === 1)) { - // fill recipient with administrators address to prevent problems with provider - $this->addAddress($gSettingsManager->getString('email_administrator'), $gL10n->get('SYS_ADMINISTRATOR')); - } - - // add all recipients as bcc to the mail - foreach ($recipientsArray as $recipientBCC) { - // remove only all BCC because to-address could be explicit set if undisclosed recipients won't work - $this->clearBCCs(); - $this->addBCC($recipientBCC['address'], $recipientBCC['name']); - if ($gDebug) { - $gLogger->notice('Email send as BCC to ' . $recipientBCC['name'] . ' (' . $recipientBCC['address'] . ')'); - } - - // add body to the email - if ($this->emSendAsHTML) { - $html = $this->setUserSpecificTemplateText($this->emHtmlText, $recipientBCC['firstname'], $recipientBCC['surname'], $recipientBCC['address'], $recipientBCC['name']); - $this->msgHTML($html); - } else { - $txt = $this->setUserSpecificTemplateText($this->emText, $recipientBCC['firstname'], $recipientBCC['surname'], $recipientBCC['address'], $recipientBCC['name']); - $this->Body = $txt; - } - - // now send mail - $this->send(); - } } } catch (Exception $e) { return $e->errorMessage(); From 5b229936cdc8e69d77690eb8a1a47d491c7b53d2 Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Thu, 18 Aug 2022 22:50:07 +0200 Subject: [PATCH 03/14] Revert settings --- adm_program/modules/preferences/preferences.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/adm_program/modules/preferences/preferences.php b/adm_program/modules/preferences/preferences.php index 64dcf47aad..1b32e369b6 100644 --- a/adm_program/modules/preferences/preferences.php +++ b/adm_program/modules/preferences/preferences.php @@ -513,6 +513,19 @@ function getPreferencePanel($group, $id, $parentId, $title, $icon, $body) $formValues['mail_sendmail_name'], array('maxLength' => 50, 'helpTextIdInline' => 'SYS_SENDER_NAME_DESC') ); +$selectBoxEntries = array(0 => $gL10n->get('SYS_HIDDEN'), 1 => $gL10n->get('SYS_SENDER'), 2 => $gL10n->get('SYS_ADMINISTRATOR')); +$formEmailDispatch->addSelectBox( + 'mail_recipients_with_roles', + $gL10n->get('SYS_MULTIPLE_RECIPIENTS'), + $selectBoxEntries, + array('defaultValue' => $formValues['mail_recipients_with_roles'], 'showContextDependentFirstEntry' => false, 'helpTextIdInline' => 'SYS_MULTIPLE_RECIPIENTS_DESC') +); +$formEmailDispatch->addCheckbox( + 'mail_into_to', + $gL10n->get('SYS_INTO_TO'), + (bool) $formValues['mail_into_to'], + array('helpTextIdInline' => 'SYS_INTO_TO_DESC') +); $formEmailDispatch->addInput( 'mail_number_recipients', $gL10n->get('SYS_NUMBER_RECIPIENTS'), From c24ae198671d4d702df70aa43dbf96ba8f4ebe65 Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Thu, 18 Aug 2022 22:50:46 +0200 Subject: [PATCH 04/14] Added old logic and extend to check of bulk/single setting --- .../modules/preferences/preferences.php | 7 + adm_program/system/classes/Email.php | 151 ++++++++++-------- 2 files changed, 88 insertions(+), 70 deletions(-) diff --git a/adm_program/modules/preferences/preferences.php b/adm_program/modules/preferences/preferences.php index 1b32e369b6..d6344a8b15 100644 --- a/adm_program/modules/preferences/preferences.php +++ b/adm_program/modules/preferences/preferences.php @@ -513,6 +513,13 @@ function getPreferencePanel($group, $id, $parentId, $title, $icon, $body) $formValues['mail_sendmail_name'], array('maxLength' => 50, 'helpTextIdInline' => 'SYS_SENDER_NAME_DESC') ); +$selectBoxEntries = array(0 => $gL10n->get('SYS_MAIL_BULK'), 1 => $gL10n->get('SYS_MAIL_SINGLE')); +$formEmailDispatch->addSelectBox( + 'mail_sending_mode', + $gL10n->get('SYS_MAIL_SENDING_MODE'), + $selectBoxEntries, + array('defaultValue' => $formValues['mail_sending_mode'], 'showContextDependentFirstEntry' => false, 'helpTextIdInline' => 'SYS_MAIL_SENDING_MODE_DESC') +); $selectBoxEntries = array(0 => $gL10n->get('SYS_HIDDEN'), 1 => $gL10n->get('SYS_SENDER'), 2 => $gL10n->get('SYS_ADMINISTRATOR')); $formEmailDispatch->addSelectBox( 'mail_recipients_with_roles', diff --git a/adm_program/system/classes/Email.php b/adm_program/system/classes/Email.php index dab6389134..f5b7c0486b 100644 --- a/adm_program/system/classes/Email.php +++ b/adm_program/system/classes/Email.php @@ -73,6 +73,9 @@ class Email extends PHPMailer public const EMAIL_ONLY_ACTIVE_MEMBERS = 1; public const EMAIL_ONLY_FORMER_MEMBERS = 2; + public const SENDINGMODE_BULK = 1; + public const SENDINGMODE_SINGLE = 1; + /** * @var string Plain text of email */ @@ -101,6 +104,10 @@ class Email extends PHPMailer * @var bool */ private $emSendAsHTML = false; + /** + * @var int The sending mode from the settings: 0 = BULK, 1 = SINGLE + */ + private $sendingMode = Email::SENDINGMODE_BULK; /** * @var array> */ @@ -139,6 +146,7 @@ public function __construct() $this->isMail(); } + $this->sendingMode = $gSettingsManager->getInt('mail_sending_mode'); // set language for error reporting $this->setLanguage($gL10n->getLanguageIsoCode()); $this->CharSet = $gSettingsManager->getString('mail_character_encoding'); @@ -608,52 +616,6 @@ public function setText($text) $this->emHtmlText .= $text; } - /** - * Sends a copy of the mail back to the sender. If the flag emListRecipients it set than all - * recipients will be listed in the mail. - * @throws \PHPMailer\PHPMailer\Exception - */ - private function sendCopyMail() - { - global $gL10n; - - // remove all recipients - $this->clearAllRecipients(); - - $this->Subject = $gL10n->get('SYS_CARBON_COPY') . ': ' . $this->Subject; - - // add a separate header with info of the copy mail - if ($this->emSendAsHTML) { - $copyHeader = $gL10n->get('SYS_COPY_OF_YOUR_EMAIL') . ':' . static::$LE . '
' . - static::$LE . static::$LE; - } else { - $copyHeader = $gL10n->get('SYS_COPY_OF_YOUR_EMAIL') . ':' . static::$LE . - '*****************************************************************************************************************************' . - static::$LE . static::$LE; - } - - // if the flag emListRecipients is set than list all recipients of the mail - if ($this->emListRecipients) { - $copyHeader = $gL10n->get('SYS_MESSAGE_WENT_TO').':' . static::$LE . static::$LE . - implode(static::$LE, $this->emRecipientsNames) . static::$LE . static::$LE . $copyHeader; - } - - $this->emText = $copyHeader . $this->emText; - $this->emHtmlText = nl2br($copyHeader) . $this->emHtmlText; - - // add the text of the message - if ($this->emSendAsHTML) { - $this->msgHTML($this->emHtmlText); - } else { - $this->Body = $this->emText; - } - - // now set the sender of the original mail as the recipients of the copy mail - $this->addAddress($this->emSender['address'], $this->emSender['name']); - - $this->send(); - } - /** * Method will send the email to all recipients. Therefore, the method will evaluate how to send the email. * If it's necessary all recipients will be added to BCC and also smaller packages of recipients will be @@ -662,38 +624,87 @@ private function sendCopyMail() */ public function sendEmail() { - global $gSettingsManager, $gLogger, $gDebug; - + global $gSettingsManager, $gLogger, $gDebug, $gValidLogin, $gCurrentUser; try { - // if there is a limit of email recipients than split the recipients into smaller packages - $recipientsArrays = array_chunk($this->emRecipientsArray, $gSettingsManager->getInt('mail_number_recipients')); + // If sending mode is "SINGLE" every E-mail is send on its own, so we do not need to check anything else here + if($this->sendingMode == Email::SENDINGMODE_SINGLE) { + foreach ($this->emRecipientsArray as $recipient) { + $this->clearAllRecipients(); + $this->addAddress($recipient['address'], $recipient['name']); + if ($gDebug) { + $gLogger->notice('Email send as TO to ' . $recipient['name'] . ' (' . $recipient['address'] . ')'); + } + + // add body to the email + if ($this->emSendAsHTML) { + $html = $this->setUserSpecificTemplateText($this->emHtmlText, $recipient['firstname'], $recipient['surname'], $recipient['address'], $recipient['name']); + $this->msgHTML($html); + } else { + $txt = $this->setUserSpecificTemplateText($this->emText, $recipient['firstname'], $recipient['surname'], $recipient['address'], $recipient['name']); + $this->Body = $txt; + } + + // now send mail + $this->send(); + } + } else { + // add body to the email + if ($this->emSendAsHTML) { + $this->msgHTML($this->emHtmlText); + } else { + $this->Body = $this->emText; + } + + // if there is a limit of email recipients than split the recipients into smaller packages + $recipientsArrays = array_chunk($this->emRecipientsArray, $gSettingsManager->getInt('mail_number_recipients')); - foreach ($recipientsArrays as $recipientsArray) { - try { - // add all recipients as bcc to the mail - foreach ($recipientsArray as $recipient) { + foreach ($recipientsArrays as $recipientsArray) { + // if number of bcc recipients = 1 then send the mail directly to the user and not as bcc + if ($this->countRecipients() === 1) { + // remove all current recipients from mail $this->clearAllRecipients(); - $this->addAddress($recipient['address'], $recipient['name']); + + $this->addAddress($recipientsArray[0]['address'], $recipientsArray[0]['name']); if ($gDebug) { - $gLogger->notice('Email send as TO to ' . $recipient['name'] . ' (' . $recipient['address'] . ')'); + $gLogger->notice('Email send as TO to ' . $recipientsArray[0]['name'] . ' (' . $recipientsArray[0]['address'] . ')'); + } + } elseif ($gSettingsManager->getBool('mail_into_to')) { + // remove all current recipients from mail + $this->clearAllRecipients(); + + // add all recipients as bcc to the mail + foreach ($recipientsArray as $recipientTO) { + $this->addAddress($recipientTO['address'], $recipientTO['name']); + if ($gDebug) { + $gLogger->notice('Email send as TO to ' . $recipientTO['name'] . ' (' . $recipientTO['address'] . ')'); + } + } + } else { + // remove only all BCC because to-address could be explicit set if undisclosed recipients won't work + $this->clearBCCs(); + + // normally we need no To-address and set "undisclosed recipients", but if + // that won't work than the following address will be set + if ($gValidLogin && (int) $gSettingsManager->get('mail_recipients_with_roles') === 1) { + // fill recipient with sender address to prevent problems with provider + $this->addAddress($gCurrentUser->getValue('EMAIL'), $gCurrentUser->getValue('FIRST_NAME').' '.$gCurrentUser->getValue('LAST_NAME')); + } elseif ((int) $gSettingsManager->get('mail_recipients_with_roles') === 2 + || (!$gValidLogin && (int) $gSettingsManager->get('mail_recipients_with_roles') === 1)) { + // fill recipient with administrators address to prevent problems with provider + $this->addAddress($gSettingsManager->getString('email_administrator'), $gL10n->get('SYS_ADMINISTRATOR')); } - // add body to the email - if ($this->emSendAsHTML) { - $html = $this->setUserSpecificTemplateText($this->emHtmlText, $recipient['firstname'], $recipient['surname'], $recipient['address'], $recipient['name']); - $this->msgHTML($html); - } else { - $txt = $this->setUserSpecificTemplateText($this->emText, $recipient['firstname'], $recipient['surname'], $recipient['address'], $recipient['name']); - $this->Body = $txt; + // add all recipients as bcc to the mail + foreach ($recipientsArray as $recipientBCC) { + $this->addBCC($recipientBCC['address'], $recipientBCC['name']); + if ($gDebug) { + $gLogger->notice('Email send as BCC to ' . $recipientBCC['name'] . ' (' . $recipientBCC['address'] . ')'); + } } - - // now send mail - $this->send(); } - } catch (Exception $e) { - return $e->errorMessage(); - } catch (\Exception $e) { - return $e->getMessage(); + + // now send mail + $this->send(); } } // now send the email as a copy to the sender From 421ecbd2b08dd10111d597ce5319a6695bbc0d45 Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Fri, 19 Aug 2022 08:57:01 +0200 Subject: [PATCH 05/14] Extended documentation --- adm_program/system/classes/Email.php | 1 + 1 file changed, 1 insertion(+) diff --git a/adm_program/system/classes/Email.php b/adm_program/system/classes/Email.php index f5b7c0486b..3cd4b60eb2 100644 --- a/adm_program/system/classes/Email.php +++ b/adm_program/system/classes/Email.php @@ -620,6 +620,7 @@ public function setText($text) * Method will send the email to all recipients. Therefore, the method will evaluate how to send the email. * If it's necessary all recipients will be added to BCC and also smaller packages of recipients will be * created. So maybe several emails will be send. Also a copy to the sender will be send if the preferences are set. + * If the Sending Mode is set to "SINGLE" every e-mail will be send on its own, so there will be send out a lot e-mails. * @return true|string */ public function sendEmail() From a76239fc003d187c9d9be408324fc578bd7660ed Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Fri, 19 Aug 2022 09:31:39 +0200 Subject: [PATCH 06/14] // WIP added Language --- adm_program/languages/en.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adm_program/languages/en.xml b/adm_program/languages/en.xml index 04d30ebb19..2a215fb781 100644 --- a/adm_program/languages/en.xml +++ b/adm_program/languages/en.xml @@ -1039,6 +1039,10 @@ Move #VAR1# Multiple recipients E-mails to multiple recipients contain all recipients in the BCC field. This ensures that nobody sees the e-mail addresses of the other recipients. However, the TO field must also be filled. This setting can be used to define what is entered in the recipient (TO) field. This could be a hidden value "Undisclosed Recipients", but this causes problems with some providers. Alternatively the recipient field (TO) can be filled with the sender address or the administrator address from the system notifications. Note: All emails to multiple recipients will then also be sent to the email address in the recipient field (TO). (Default: Sender) + E-mail sending mode + When sending emails as "Bulk", the recipients are entered in the TO or BCC field. When sent as "Single", each email is sent individually, giving you additional placeholders and personalization options. + Bulk recipients + Single recipients The role \'administrator\' must have at least one member assigned! Here you can define conditions for each field in your list. This will further restrict the determined members of the selected role with your conditions. Name From adf0f6ae6b0281ad1a278f6a7ec5ec309e887488 Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Fri, 19 Aug 2022 09:42:28 +0200 Subject: [PATCH 07/14] Only show mail options for bcc/to when SendingMode is BULK --- .../modules/preferences/preferences.php | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/adm_program/modules/preferences/preferences.php b/adm_program/modules/preferences/preferences.php index d6344a8b15..19c4d07886 100644 --- a/adm_program/modules/preferences/preferences.php +++ b/adm_program/modules/preferences/preferences.php @@ -520,25 +520,31 @@ function getPreferencePanel($group, $id, $parentId, $title, $icon, $body) $selectBoxEntries, array('defaultValue' => $formValues['mail_sending_mode'], 'showContextDependentFirstEntry' => false, 'helpTextIdInline' => 'SYS_MAIL_SENDING_MODE_DESC') ); -$selectBoxEntries = array(0 => $gL10n->get('SYS_HIDDEN'), 1 => $gL10n->get('SYS_SENDER'), 2 => $gL10n->get('SYS_ADMINISTRATOR')); -$formEmailDispatch->addSelectBox( - 'mail_recipients_with_roles', - $gL10n->get('SYS_MULTIPLE_RECIPIENTS'), - $selectBoxEntries, - array('defaultValue' => $formValues['mail_recipients_with_roles'], 'showContextDependentFirstEntry' => false, 'helpTextIdInline' => 'SYS_MULTIPLE_RECIPIENTS_DESC') -); -$formEmailDispatch->addCheckbox( - 'mail_into_to', - $gL10n->get('SYS_INTO_TO'), - (bool) $formValues['mail_into_to'], - array('helpTextIdInline' => 'SYS_INTO_TO_DESC') -); -$formEmailDispatch->addInput( - 'mail_number_recipients', - $gL10n->get('SYS_NUMBER_RECIPIENTS'), - $formValues['mail_number_recipients'], - array('type' => 'number', 'minNumber' => 0, 'maxNumber' => 9999, 'step' => 1, 'helpTextIdInline' => 'SYS_NUMBER_RECIPIENTS_DESC') -); + +$sendingMode = $gSettingsManager->getInt('mail_sending_mode'); + +// Only show this options if SendingMode = 0 / SYS_MAIL_BULK +if($sendingMode == 0) { + $selectBoxEntries = array(0 => $gL10n->get('SYS_HIDDEN'), 1 => $gL10n->get('SYS_SENDER'), 2 => $gL10n->get('SYS_ADMINISTRATOR')); + $formEmailDispatch->addSelectBox( + 'mail_recipients_with_roles', + $gL10n->get('SYS_MULTIPLE_RECIPIENTS'), + $selectBoxEntries, + array('defaultValue' => $formValues['mail_recipients_with_roles'], 'showContextDependentFirstEntry' => false, 'helpTextIdInline' => 'SYS_MULTIPLE_RECIPIENTS_DESC') + ); + $formEmailDispatch->addCheckbox( + 'mail_into_to', + $gL10n->get('SYS_INTO_TO'), + (bool) $formValues['mail_into_to'], + array('helpTextIdInline' => 'SYS_INTO_TO_DESC') + ); + $formEmailDispatch->addInput( + 'mail_number_recipients', + $gL10n->get('SYS_NUMBER_RECIPIENTS'), + $formValues['mail_number_recipients'], + array('type' => 'number', 'minNumber' => 0, 'maxNumber' => 9999, 'step' => 1, 'helpTextIdInline' => 'SYS_NUMBER_RECIPIENTS_DESC') + ); +} $selectBoxEntries = array('iso-8859-1' => $gL10n->get('SYS_ISO_8859_1'), 'utf-8' => $gL10n->get('SYS_UTF8')); $formEmailDispatch->addSelectBox( 'mail_character_encoding', From 52745ee6338271894388d6e237bb08c720a48aff Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Fri, 19 Aug 2022 09:44:49 +0200 Subject: [PATCH 08/14] Added default preferences --- adm_program/installation/db_scripts/preferences.php | 1 + 1 file changed, 1 insertion(+) diff --git a/adm_program/installation/db_scripts/preferences.php b/adm_program/installation/db_scripts/preferences.php index b10c6ced80..8e787aa1a5 100644 --- a/adm_program/installation/db_scripts/preferences.php +++ b/adm_program/installation/db_scripts/preferences.php @@ -49,6 +49,7 @@ // E-mail dispatch 'mail_send_method' => 'phpmail', + 'mail_sending_mode' => '0', 'mail_recipients_with_roles' => '1', 'mail_number_recipients' => '50', 'mail_into_to' => '0', From 4d7b8a0e7a7bc4c15c489d15775c7efc6960fab3 Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Fri, 19 Aug 2022 14:36:15 +0200 Subject: [PATCH 09/14] Changed and added language --- adm_program/languages/de-DE.xml | 4 ++++ adm_program/languages/de.xml | 4 ++++ adm_program/languages/en.xml | 6 +++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/adm_program/languages/de-DE.xml b/adm_program/languages/de-DE.xml index 9e5d3d59fc..8b634a0763 100644 --- a/adm_program/languages/de-DE.xml +++ b/adm_program/languages/de-DE.xml @@ -1043,6 +1043,10 @@ #VAR1# verschieben Mehrere Empfänger:innen E-Mails an mehrere Empfänger:innen enthalten alle Empfänger:innen im BCC-Feld. Damit ist sichergestellt, dass keiner die E-Mail-Adressen der anderen Empfänger:innen sieht. Das TO-Feld muss allerdings auch befüllt werden. Über diese Einstellung kann festgelegt werden, was im Empfängerfeld (TO) hinterlegt wird. Dies kein ein versteckter Wert \"Undisclosed Recipients\" sein, was aber bei manchen Providern zu Problemen führt. Alternativ kann das Empfängerfeld (TO) mit der Absenderadresse bzw. der Administrator:innen-Adresse aus den Systembenachrichtigungen gefüllt werden. Hinweis: Alle Emails an mehrere Empfänger:innen werden dann auch an die E-Mail-Adresse im Empfängerfeld (TO) geschickt. (Voreinstellung: Absender:in) + E-mail Versand + Im Modus "Gebündelter versandt" werden E-Mails in einer oder mehrerer gebündelten E-Mails versendet. Dabei werden die Empfänger als BCC oder TO eingefügt. Im Modus "Einzelempfänger" wird jede E-Mail einzeln an den entsprechenden Empfänger im TO Feld versendet. In diesem Modus gibt es weitere Platzhalter die verwendet werden können:\nEmpfänger Vorname:\n#receiver_first_name# #receiver_firstname# #receiver_surname#\nEmpfänger Nachname:\n#receiver_lastname#\nEmpfänger E-Mail:\n#receiver_email#\nEmpfänger Name:\n#receiver_name# + Gebündelter versandt + Einzelempfänger Die Rolle Administrator:in muss mindestens ein Mitglied haben! Hier können Sie Bedingungen zu jedem Feld in Ihrer Liste hinterlegen. Damit werden die ermittelten Mitglieder der ausgewählten Rolle mit Ihren Bedingungen weiter eingeschränkt. Name diff --git a/adm_program/languages/de.xml b/adm_program/languages/de.xml index 25cf96e179..95b28607b7 100644 --- a/adm_program/languages/de.xml +++ b/adm_program/languages/de.xml @@ -1039,6 +1039,10 @@ #VAR1# verschieben Mehrere Empfänger:innen E-Mails an mehrere Empfänger:innen enthalten alle Empfänger:innen im BCC-Feld. Damit ist sichergestellt, dass keiner die E-Mail-Adressen der anderen Empfänger:innen sieht. Das TO-Feld muss allerdings auch befüllt werden. Über diese Einstellung kann festgelegt werden, was im Empfängerfeld (TO) hinterlegt wird. Dies kein ein versteckter Wert \"Undisclosed Recipients\" sein, was aber bei manchen Providern zu Problemen führt. Alternativ kann das Empfängerfeld (TO) mit der Absenderadresse bzw. der Administrator:innen-Adresse aus den Systembenachrichtigungen gefüllt werden. Hinweis: Alle Emails an mehrere Empfänger:innen werden dann auch an die E-Mail-Adresse im Empfängerfeld (TO) geschickt. (Voreinstellung: Absender:in) + E-mail Versand + Im Modus "Gebündelter versandt" werden E-Mails in einer oder mehrerer gebündelten E-Mails versendet. Dabei werden die Empfänger als BCC oder TO eingefügt. Im Modus "Einzelempfänger" wird jede E-Mail einzeln an den entsprechenden Empfänger im TO Feld versendet. In diesem Modus gibt es weitere Platzhalter die verwendet werden können:\nEmpfänger Vorname:\n#receiver_first_name# #receiver_firstname# #receiver_surname#\nEmpfänger Nachname:\n#receiver_lastname#\nEmpfänger E-Mail:\n#receiver_email#\nEmpfänger Name:\n#receiver_name# + Gebündelter versandt + Einzelempfänger Die Rolle Administrator:in muss mindestens ein Mitglied haben! Hier kannst du Bedingungen zu jedem Feld in deiner Liste hinterlegen. Damit werden die ermittelten Mitglieder der ausgewählten Rolle mit deinen Bedingungen weiter eingeschränkt. Name diff --git a/adm_program/languages/en.xml b/adm_program/languages/en.xml index 2a215fb781..fee607b672 100644 --- a/adm_program/languages/en.xml +++ b/adm_program/languages/en.xml @@ -1040,9 +1040,9 @@ Multiple recipients E-mails to multiple recipients contain all recipients in the BCC field. This ensures that nobody sees the e-mail addresses of the other recipients. However, the TO field must also be filled. This setting can be used to define what is entered in the recipient (TO) field. This could be a hidden value "Undisclosed Recipients", but this causes problems with some providers. Alternatively the recipient field (TO) can be filled with the sender address or the administrator address from the system notifications. Note: All emails to multiple recipients will then also be sent to the email address in the recipient field (TO). (Default: Sender) E-mail sending mode - When sending emails as "Bulk", the recipients are entered in the TO or BCC field. When sent as "Single", each email is sent individually, giving you additional placeholders and personalization options. - Bulk recipients - Single recipients + In the "Bundled sent" mode, emails are sent in one or more bundled emails. The recipients are inserted as BCC or TO. In the "Single recipient" mode, each e-mail is sent individually to the corresponding recipient in the TO field. In this mode there are additional placeholders that can be used:\nReceiver first name:\n#receiver_first_name# #receiver_firstname# #receiver_surname#\nReceiver last name:\n#receiver_lastname#\nReceiver email:\n#receiver_email#\nReceiver name:\n#receiver_name# + Bundled sent + Single recipient The role \'administrator\' must have at least one member assigned! Here you can define conditions for each field in your list. This will further restrict the determined members of the selected role with your conditions. Name From 23821972b670896b800ce44cfdad5f9e57088c15 Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Sun, 21 Aug 2022 19:40:29 +0200 Subject: [PATCH 10/14] Fixed methods due to change of signature in addRecipient --- adm_program/modules/ecards/ecard_function.php | 4 ++-- adm_program/modules/ecards/ecard_send.php | 4 ++-- adm_program/system/classes/UserRegistration.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/adm_program/modules/ecards/ecard_function.php b/adm_program/modules/ecards/ecard_function.php index bbcc7fccc6..2dbe7cf4ab 100644 --- a/adm_program/modules/ecards/ecard_function.php +++ b/adm_program/modules/ecards/ecard_function.php @@ -156,7 +156,7 @@ public function parseEcardTemplate($imageName, $ecardMessage, $ecardData, $recip * @param string $photoServerPath der Pfad wo die Bilder in der Grußkarte am Server liegen * @return bool|string */ - public function sendEcard($senderName, $senderEmail, $ecardHtmlData, $recipientName, $recipientEmail, $photoServerPath) + public function sendEcard($senderName, $senderEmail, $ecardHtmlData, $recipientFirstName, $recipientName, $recipientEmail, $photoServerPath) { global $gSettingsManager, $gLogger; @@ -166,7 +166,7 @@ public function sendEcard($senderName, $senderEmail, $ecardHtmlData, $recipientN $email = new Email(); $email->setSender($senderEmail, $senderName); $email->setSubject($this->newMessageReceivedString); - $email->addRecipient($recipientEmail, $recipientName); + $email->addRecipient($recipientEmail, $recipientFirstName, $recipientName); // alle Bilder werden aus dem Template herausgeholt, damit diese als Anhang verschickt werden koennen if (preg_match_all('/()/Uim', $ecardHtmlData, $matchArray)) { diff --git a/adm_program/modules/ecards/ecard_send.php b/adm_program/modules/ecards/ecard_send.php index c96c227c42..d494eba2ef 100644 --- a/adm_program/modules/ecards/ecard_send.php +++ b/adm_program/modules/ecards/ecard_send.php @@ -144,7 +144,7 @@ if ($ecardSendResult) { // create and send ecard $ecardHtmlData = $funcClass->parseEcardTemplate($imageUrl, $postMessage, $ecardDataToParse, $row['first_name'].' '.$row['last_name'], $row['email']); - $ecardSendResult = $funcClass->sendEcard($senderName, $senderEmail, $ecardHtmlData, $row['first_name'].' '.$row['last_name'], $row['email'], $imageServerPath); + $ecardSendResult = $funcClass->sendEcard($senderName, $senderEmail, $ecardHtmlData, $row['first_name'], $row['last_name'], $row['email'], $imageServerPath); } } @@ -183,7 +183,7 @@ if ($ecardSendResult) { // create and send ecard $ecardHtmlData = $funcClass->parseEcardTemplate($imageUrl, $postMessage, $ecardDataToParse, $row['first_name'].' '.$row['last_name'], $row['email']); - $ecardSendResult = $funcClass->sendEcard($senderName, $senderEmail, $ecardHtmlData, $row['first_name'].' '.$row['last_name'], $row['email'], $imageServerPath); + $ecardSendResult = $funcClass->sendEcard($senderName, $senderEmail, $ecardHtmlData, $row['first_name'], $row['last_name'], $row['email'], $imageServerPath); } } diff --git a/adm_program/system/classes/UserRegistration.php b/adm_program/system/classes/UserRegistration.php index 7fe447e6bf..f9985d7ba6 100644 --- a/adm_program/system/classes/UserRegistration.php +++ b/adm_program/system/classes/UserRegistration.php @@ -263,7 +263,7 @@ public function save($updateFingerPrint = true) while ($row = $emailStatement->fetch()) { // send mail that a new registration is available $sysmail = new SystemMail($this->db); - $sysmail->addRecipient($row['email'], $row['first_name']. ' '. $row['last_name']); + $sysmail->addRecipient($row['email'], $row['first_name'], $row['last_name']); $sysmail->sendSystemMail('SYSMAIL_REGISTRATION_WEBMASTER', $this); // TODO Exception handling } } From f8537866e8282fd7fa716ef9b754b79eb2498386 Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Sun, 21 Aug 2022 19:43:52 +0200 Subject: [PATCH 11/14] SendCopyMail restored because it was deleted unintentionally --- adm_program/system/classes/Email.php | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/adm_program/system/classes/Email.php b/adm_program/system/classes/Email.php index 3cd4b60eb2..9f40d28f10 100644 --- a/adm_program/system/classes/Email.php +++ b/adm_program/system/classes/Email.php @@ -616,6 +616,52 @@ public function setText($text) $this->emHtmlText .= $text; } + /** + * Sends a copy of the mail back to the sender. If the flag emListRecipients it set than all + * recipients will be listed in the mail. + * @throws \PHPMailer\PHPMailer\Exception + */ + private function sendCopyMail() + { + global $gL10n; + + // remove all recipients + $this->clearAllRecipients(); + + $this->Subject = $gL10n->get('SYS_CARBON_COPY') . ': ' . $this->Subject; + + // add a separate header with info of the copy mail + if ($this->emSendAsHTML) { + $copyHeader = $gL10n->get('SYS_COPY_OF_YOUR_EMAIL') . ':' . static::$LE . '
' . + static::$LE . static::$LE; + } else { + $copyHeader = $gL10n->get('SYS_COPY_OF_YOUR_EMAIL') . ':' . static::$LE . + '*****************************************************************************************************************************' . + static::$LE . static::$LE; + } + + // if the flag emListRecipients is set than list all recipients of the mail + if ($this->emListRecipients) { + $copyHeader = $gL10n->get('SYS_MESSAGE_WENT_TO').':' . static::$LE . static::$LE . + implode(static::$LE, $this->emRecipientsNames) . static::$LE . static::$LE . $copyHeader; + } + + $this->emText = $copyHeader . $this->emText; + $this->emHtmlText = nl2br($copyHeader) . $this->emHtmlText; + + // add the text of the message + if ($this->emSendAsHTML) { + $this->msgHTML($this->emHtmlText); + } else { + $this->Body = $this->emText; + } + + // now set the sender of the original mail as the recipients of the copy mail + $this->addAddress($this->emSender['address'], $this->emSender['name']); + + $this->send(); + } + /** * Method will send the email to all recipients. Therefore, the method will evaluate how to send the email. * If it's necessary all recipients will be added to BCC and also smaller packages of recipients will be From 24a20961b558b5cd116917071229cd7c0c485806 Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Sun, 21 Aug 2022 22:47:44 +0200 Subject: [PATCH 12/14] Changed show/hide to js handled --- .../modules/preferences/preferences.php | 60 ++++++++++++------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/adm_program/modules/preferences/preferences.php b/adm_program/modules/preferences/preferences.php index 19c4d07886..2fc53cbc41 100644 --- a/adm_program/modules/preferences/preferences.php +++ b/adm_program/modules/preferences/preferences.php @@ -513,6 +513,24 @@ function getPreferencePanel($group, $id, $parentId, $title, $icon, $body) $formValues['mail_sendmail_name'], array('maxLength' => 50, 'helpTextIdInline' => 'SYS_SENDER_NAME_DESC') ); + +// Add js to show or hide mail options +$page->addJavascript(' + $(function(){ + var fieldsToHideOnSingleMode = "#mail_recipients_with_roles_group, #mail_into_to_group, #mail_number_recipients_group"; + if($("#mail_sending_mode").val() == 1) { + $(fieldsToHideOnSingleMode).hide(); + } + $("#mail_sending_mode").on("change", function() { + if($("#mail_sending_mode").val() == 1) { + $(fieldsToHideOnSingleMode).hide(); + } else { + $(fieldsToHideOnSingleMode).show(); + } + }); + }); +'); + $selectBoxEntries = array(0 => $gL10n->get('SYS_MAIL_BULK'), 1 => $gL10n->get('SYS_MAIL_SINGLE')); $formEmailDispatch->addSelectBox( 'mail_sending_mode', @@ -521,30 +539,26 @@ function getPreferencePanel($group, $id, $parentId, $title, $icon, $body) array('defaultValue' => $formValues['mail_sending_mode'], 'showContextDependentFirstEntry' => false, 'helpTextIdInline' => 'SYS_MAIL_SENDING_MODE_DESC') ); -$sendingMode = $gSettingsManager->getInt('mail_sending_mode'); +$selectBoxEntries = array(0 => $gL10n->get('SYS_HIDDEN'), 1 => $gL10n->get('SYS_SENDER'), 2 => $gL10n->get('SYS_ADMINISTRATOR')); +$formEmailDispatch->addSelectBox( + 'mail_recipients_with_roles', + $gL10n->get('SYS_MULTIPLE_RECIPIENTS'), + $selectBoxEntries, + array('defaultValue' => $formValues['mail_recipients_with_roles'], 'showContextDependentFirstEntry' => false, 'helpTextIdInline' => 'SYS_MULTIPLE_RECIPIENTS_DESC') +); +$formEmailDispatch->addCheckbox( + 'mail_into_to', + $gL10n->get('SYS_INTO_TO'), + (bool) $formValues['mail_into_to'], + array('helpTextIdInline' => 'SYS_INTO_TO_DESC') +); +$formEmailDispatch->addInput( + 'mail_number_recipients', + $gL10n->get('SYS_NUMBER_RECIPIENTS'), + $formValues['mail_number_recipients'], + array('type' => 'number', 'minNumber' => 0, 'maxNumber' => 9999, 'step' => 1, 'helpTextIdInline' => 'SYS_NUMBER_RECIPIENTS_DESC') +); -// Only show this options if SendingMode = 0 / SYS_MAIL_BULK -if($sendingMode == 0) { - $selectBoxEntries = array(0 => $gL10n->get('SYS_HIDDEN'), 1 => $gL10n->get('SYS_SENDER'), 2 => $gL10n->get('SYS_ADMINISTRATOR')); - $formEmailDispatch->addSelectBox( - 'mail_recipients_with_roles', - $gL10n->get('SYS_MULTIPLE_RECIPIENTS'), - $selectBoxEntries, - array('defaultValue' => $formValues['mail_recipients_with_roles'], 'showContextDependentFirstEntry' => false, 'helpTextIdInline' => 'SYS_MULTIPLE_RECIPIENTS_DESC') - ); - $formEmailDispatch->addCheckbox( - 'mail_into_to', - $gL10n->get('SYS_INTO_TO'), - (bool) $formValues['mail_into_to'], - array('helpTextIdInline' => 'SYS_INTO_TO_DESC') - ); - $formEmailDispatch->addInput( - 'mail_number_recipients', - $gL10n->get('SYS_NUMBER_RECIPIENTS'), - $formValues['mail_number_recipients'], - array('type' => 'number', 'minNumber' => 0, 'maxNumber' => 9999, 'step' => 1, 'helpTextIdInline' => 'SYS_NUMBER_RECIPIENTS_DESC') - ); -} $selectBoxEntries = array('iso-8859-1' => $gL10n->get('SYS_ISO_8859_1'), 'utf-8' => $gL10n->get('SYS_UTF8')); $formEmailDispatch->addSelectBox( 'mail_character_encoding', From 100e510d197578a31549575f18e2bb2ee65748f7 Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Thu, 25 Aug 2022 22:23:39 +0200 Subject: [PATCH 13/14] Changed Name to LastName in several variables --- adm_program/modules/ecards/ecard_function.php | 7 ++--- adm_program/system/classes/Email.php | 27 +++++++++---------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/adm_program/modules/ecards/ecard_function.php b/adm_program/modules/ecards/ecard_function.php index 2dbe7cf4ab..b57f72d613 100644 --- a/adm_program/modules/ecards/ecard_function.php +++ b/adm_program/modules/ecards/ecard_function.php @@ -151,12 +151,13 @@ public function parseEcardTemplate($imageName, $ecardMessage, $ecardData, $recip * @param string $senderName * @param string $senderEmail * @param string $ecardHtmlData geparste Daten vom Template - * @param string $recipientName der Name des Empfaengers + * @param string $recipientFirstName der Name des Empfaengers + * @param string $recipientLastName der Name des Empfaengers * @param string $recipientEmail die Email des Empfaengers * @param string $photoServerPath der Pfad wo die Bilder in der Grußkarte am Server liegen * @return bool|string */ - public function sendEcard($senderName, $senderEmail, $ecardHtmlData, $recipientFirstName, $recipientName, $recipientEmail, $photoServerPath) + public function sendEcard($senderName, $senderEmail, $ecardHtmlData, $recipientFirstName, $recipientLastName, $recipientEmail, $photoServerPath) { global $gSettingsManager, $gLogger; @@ -166,7 +167,7 @@ public function sendEcard($senderName, $senderEmail, $ecardHtmlData, $recipientF $email = new Email(); $email->setSender($senderEmail, $senderName); $email->setSubject($this->newMessageReceivedString); - $email->addRecipient($recipientEmail, $recipientFirstName, $recipientName); + $email->addRecipient($recipientEmail, $recipientFirstName, $recipientLastName); // alle Bilder werden aus dem Template herausgeholt, damit diese als Anhang verschickt werden koennen if (preg_match_all('/()/Uim', $ecardHtmlData, $matchArray)) { diff --git a/adm_program/system/classes/Email.php b/adm_program/system/classes/Email.php index 9f40d28f10..ad3b6862c2 100644 --- a/adm_program/system/classes/Email.php +++ b/adm_program/system/classes/Email.php @@ -157,22 +157,23 @@ public function __construct() * in the recipients list. The decision if the recipient will be sent as TO or BCC will be done later * in the email send process. * @param string $address A valid email address to which the email should be sent. - * @param string $name The name of the recipient that will be shown in the email header. + * @param string $firstName The first name of the recipient that will be shown in the email header. + * @param string $lastName The last name of the recipient that will be shown in the email header. * @param array $additionalFields Additional fields to map in a Key Value like Array. Not used at all yet. * @return bool Returns **true** if the address was added to the recipients list. */ - public function addRecipient($address, $firstName = '', $name = '', $additionalFields = array()) + public function addRecipient($address, $firstName = '', $lastName = '', $additionalFields = array()) { // Recipients must be Ascii-US formatted, so encode in MimeHeader - $asciiName = stripslashes($firstName . ' ' . $name); + $asciiName = stripslashes($firstName . ' ' . $lastName); // check if valid email address and if email not in the recipients array if (StringUtils::strValidCharacters($address, 'email') && array_search($address, array_column($this->emRecipientsArray, 'address')) === false) { - $recipient = array('name' => $asciiName, 'address' => $address, 'firstname' => $firstName, 'surname' => $name); + $recipient = array('name' => $asciiName, 'address' => $address, 'firstname' => $firstName, 'surname' => $lastName); $recipient = array_merge($recipient , $additionalFields); $this->emRecipientsArray[] = $recipient; - $this->emRecipientsNames[] = $firstName . ' ' . $name; + $this->emRecipientsNames[] = $firstName . ' ' . $lastName; return true; } @@ -332,20 +333,20 @@ public function addRecipientsByUserId($userId) /** * method adds CC recipients to mail * @param string $address - * @param string $name + * @param string $lastName * @return true|string */ - public function addCopy($address, $firstName = '', $name = '') + public function addCopy($address, $firstName = '', $lastName = '') { try { - $this->addCC($address, $firstName .' '. $name); + $this->addCC($address, $firstName .' '. $lastName); } catch (Exception $e) { return $e->errorMessage(); } catch (\Exception $e) { return $e->getMessage(); } - $this->emRecipientsNames[] = $name; + $this->emRecipientsNames[] = $lastName; return true; } @@ -354,13 +355,13 @@ public function addCopy($address, $firstName = '', $name = '') * method adds BCC recipients to mail * Bcc Empfänger werden ersteinmal gesammelt, damit später Päckchen verschickt werden können * @param string $address - * @param string $name + * @param string $lastName * @return bool * @deprecated 4.2.0:4.3.0 "addBlindCopy()" is deprecated, use "addRecipient()" instead. */ - public function addBlindCopy($address, $firstName = '', $name = '') + public function addBlindCopy($address, $firstName = '', $lastName = '') { - return $this->addRecipient($address, $firstName, $name); + return $this->addRecipient($address, $firstName, $lastName); } /** @@ -593,9 +594,7 @@ public function setUserSpecificTemplateText($text, $firstName, $surname, $email, // replace parameters in email template $replaces = array( - '#receiver_first_name#' => $firstName, '#receiver_firstname#' => $firstName, - '#receiver_surname#' => $surname, '#receiver_lastname#' => $surname, '#receiver_email#' => $email, '#receiver_name#' => $name From a3845a0417852be8a3370eb54dec0ff5e6684bab Mon Sep 17 00:00:00 2001 From: Marc Horst Date: Thu, 25 Aug 2022 22:33:05 +0200 Subject: [PATCH 14/14] Updated texts and translations --- adm_program/languages/de-DE.xml | 8 ++++---- adm_program/languages/de.xml | 8 ++++---- adm_program/languages/en.xml | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/adm_program/languages/de-DE.xml b/adm_program/languages/de-DE.xml index 8b634a0763..0be5004006 100644 --- a/adm_program/languages/de-DE.xml +++ b/adm_program/languages/de-DE.xml @@ -1043,10 +1043,10 @@ #VAR1# verschieben Mehrere Empfänger:innen E-Mails an mehrere Empfänger:innen enthalten alle Empfänger:innen im BCC-Feld. Damit ist sichergestellt, dass keiner die E-Mail-Adressen der anderen Empfänger:innen sieht. Das TO-Feld muss allerdings auch befüllt werden. Über diese Einstellung kann festgelegt werden, was im Empfängerfeld (TO) hinterlegt wird. Dies kein ein versteckter Wert \"Undisclosed Recipients\" sein, was aber bei manchen Providern zu Problemen führt. Alternativ kann das Empfängerfeld (TO) mit der Absenderadresse bzw. der Administrator:innen-Adresse aus den Systembenachrichtigungen gefüllt werden. Hinweis: Alle Emails an mehrere Empfänger:innen werden dann auch an die E-Mail-Adresse im Empfängerfeld (TO) geschickt. (Voreinstellung: Absender:in) - E-mail Versand - Im Modus "Gebündelter versandt" werden E-Mails in einer oder mehrerer gebündelten E-Mails versendet. Dabei werden die Empfänger als BCC oder TO eingefügt. Im Modus "Einzelempfänger" wird jede E-Mail einzeln an den entsprechenden Empfänger im TO Feld versendet. In diesem Modus gibt es weitere Platzhalter die verwendet werden können:\nEmpfänger Vorname:\n#receiver_first_name# #receiver_firstname# #receiver_surname#\nEmpfänger Nachname:\n#receiver_lastname#\nEmpfänger E-Mail:\n#receiver_email#\nEmpfänger Name:\n#receiver_name# - Gebündelter versandt - Einzelempfänger + Versandmodus + Im Modus 'Gebündelt' werden E-Mails an mehrere Empfänger zusammengefasst. Eine E-Mail erhält dann eine konfigurierte Anzahl an Empfänger im TO oder BCC Feld. Dies ist sinnvoll, wenn der Hoster den Versand von vielen E-Mails nicht erlaubt. Im Modus 'Einzeln' erhält jeder Empfänger eine separate E-Mail. In diesem Modus können einer E-Mail-Vorlage weitere Felder hinzugefügt werden. + Gebündelt + Einzeln Die Rolle Administrator:in muss mindestens ein Mitglied haben! Hier können Sie Bedingungen zu jedem Feld in Ihrer Liste hinterlegen. Damit werden die ermittelten Mitglieder der ausgewählten Rolle mit Ihren Bedingungen weiter eingeschränkt. Name diff --git a/adm_program/languages/de.xml b/adm_program/languages/de.xml index 95b28607b7..7522fddd66 100644 --- a/adm_program/languages/de.xml +++ b/adm_program/languages/de.xml @@ -1039,10 +1039,10 @@ #VAR1# verschieben Mehrere Empfänger:innen E-Mails an mehrere Empfänger:innen enthalten alle Empfänger:innen im BCC-Feld. Damit ist sichergestellt, dass keiner die E-Mail-Adressen der anderen Empfänger:innen sieht. Das TO-Feld muss allerdings auch befüllt werden. Über diese Einstellung kann festgelegt werden, was im Empfängerfeld (TO) hinterlegt wird. Dies kein ein versteckter Wert \"Undisclosed Recipients\" sein, was aber bei manchen Providern zu Problemen führt. Alternativ kann das Empfängerfeld (TO) mit der Absenderadresse bzw. der Administrator:innen-Adresse aus den Systembenachrichtigungen gefüllt werden. Hinweis: Alle Emails an mehrere Empfänger:innen werden dann auch an die E-Mail-Adresse im Empfängerfeld (TO) geschickt. (Voreinstellung: Absender:in) - E-mail Versand - Im Modus "Gebündelter versandt" werden E-Mails in einer oder mehrerer gebündelten E-Mails versendet. Dabei werden die Empfänger als BCC oder TO eingefügt. Im Modus "Einzelempfänger" wird jede E-Mail einzeln an den entsprechenden Empfänger im TO Feld versendet. In diesem Modus gibt es weitere Platzhalter die verwendet werden können:\nEmpfänger Vorname:\n#receiver_first_name# #receiver_firstname# #receiver_surname#\nEmpfänger Nachname:\n#receiver_lastname#\nEmpfänger E-Mail:\n#receiver_email#\nEmpfänger Name:\n#receiver_name# - Gebündelter versandt - Einzelempfänger + Versandmodus + Im Modus 'Gebündelt' werden E-Mails an mehrere Empfänger zusammengefasst. Eine E-Mail erhält dann eine konfigurierte Anzahl an Empfänger im TO oder BCC Feld. Dies ist sinnvoll, wenn der Hoster den Versand von vielen E-Mails nicht erlaubt. Im Modus 'Einzeln' erhält jeder Empfänger eine separate E-Mail. In diesem Modus können einer E-Mail-Vorlage weitere Felder hinzugefügt werden. + Gebündelt + Einzeln Die Rolle Administrator:in muss mindestens ein Mitglied haben! Hier kannst du Bedingungen zu jedem Feld in deiner Liste hinterlegen. Damit werden die ermittelten Mitglieder der ausgewählten Rolle mit deinen Bedingungen weiter eingeschränkt. Name diff --git a/adm_program/languages/en.xml b/adm_program/languages/en.xml index fee607b672..3e684a2382 100644 --- a/adm_program/languages/en.xml +++ b/adm_program/languages/en.xml @@ -1040,9 +1040,9 @@ Multiple recipients E-mails to multiple recipients contain all recipients in the BCC field. This ensures that nobody sees the e-mail addresses of the other recipients. However, the TO field must also be filled. This setting can be used to define what is entered in the recipient (TO) field. This could be a hidden value "Undisclosed Recipients", but this causes problems with some providers. Alternatively the recipient field (TO) can be filled with the sender address or the administrator address from the system notifications. Note: All emails to multiple recipients will then also be sent to the email address in the recipient field (TO). (Default: Sender) E-mail sending mode - In the "Bundled sent" mode, emails are sent in one or more bundled emails. The recipients are inserted as BCC or TO. In the "Single recipient" mode, each e-mail is sent individually to the corresponding recipient in the TO field. In this mode there are additional placeholders that can be used:\nReceiver first name:\n#receiver_first_name# #receiver_firstname# #receiver_surname#\nReceiver last name:\n#receiver_lastname#\nReceiver email:\n#receiver_email#\nReceiver name:\n#receiver_name# - Bundled sent - Single recipient + In 'Bundled' mode, emails to multiple recipients are grouped together. An e-mail then receives a configured number of recipients in the TO or BCC field. This is useful if the hoster does not allow sending many emails. In 'Single' mode, each recipient receives a separate e-mail. In this mode, additional fields can be added to an email template. + Bundled + Single The role \'administrator\' must have at least one member assigned! Here you can define conditions for each field in your list. This will further restrict the determined members of the selected role with your conditions. Name