From 3125a4fe36736c25f1522f2a39a914772058d19e Mon Sep 17 00:00:00 2001 From: Torsten Oppermann <torsten@sgalinski.de> Date: Wed, 16 Aug 2017 15:36:31 +0200 Subject: [PATCH] [TASK] Use default adress from localconfig --- Classes/Service/MailTemplateService.php | 29 ++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Classes/Service/MailTemplateService.php b/Classes/Service/MailTemplateService.php index 217a1077..722d26f5 100644 --- a/Classes/Service/MailTemplateService.php +++ b/Classes/Service/MailTemplateService.php @@ -166,13 +166,20 @@ class MailTemplateService { $this->persistenceManager = $this->objectManager->get(PersistenceManager::class); // use defaultMailFromAddress if it is provided in LocalConfiguration.php; use the sg_mail TS setting as fallback - if ($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']) { + if (!filter_var($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'], FILTER_VALIDATE_EMAIL)) { $this->fromAddress = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; } else { $this->fromAddress = $this->tsSettings['mail']['default']['from']; + + if (!filter_var($this->tsSettings['mail']['default']['from'], FILTER_VALIDATE_EMAIL)) { + $this->fromAddress = 'noreply@example.org'; + } else { + $this->fromAddress = $this->tsSettings['mail']['default']['from']; + } } $this->mailMessage->setFrom($this->fromAddress); + $this->bccAddresses = GeneralUtility::trimExplode(',', $this->tsSettings['mail']['default']['bcc']); $this->ccAddresses = GeneralUtility::trimExplode(',', $this->tsSettings['mail']['default']['cc']); @@ -438,8 +445,10 @@ class MailTemplateService { $mail->setExtensionKey($extensionKey); $mail->setTemplateName($templateName); $mail->setLanguage($language); + $mail->setFromAddress($this->fromAddress); $mail->setFromName($this->fromName); + $mail->setToAddress($this->toAddresses); $mail->setMailSubject($subject); $mail->setMailBody($emailBody); @@ -645,11 +654,25 @@ class MailTemplateService { * @param Template $template */ private function loadTemplateValues($template) { - $this->setFromAddress($template->getFromMail(), $template->getFromName()); + $fromName = $template->getFromName(); + if ($fromName === '' && $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']) { + $fromName = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName']; + } + + $fromMail = $template->getFromMail(); + if (!filter_var($fromMail, FILTER_VALIDATE_EMAIL)) { + $fromMail = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress']; + if (!filter_var($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'], FILTER_VALIDATE_EMAIL)) { + $fromMail = 'noreply@example.com'; + } + } + + $this->setFromAddress($fromMail, $fromName); $this->setCcAddresses($template->getCc()); $this->setBccAddresses($template->getBcc()); $this->setReplyToAddress($template->getReplyTo()); - $this->setFromName($template->getFromName()); + $this->setFromName($fromName); + $this->setReplyToAddress($template->getReplyTo()); } -- GitLab