From 1a5f6c67230ea49c459f963147c9f0da2a035301 Mon Sep 17 00:00:00 2001 From: chrode Date: Fri, 19 Jul 2024 14:00:48 +0200 Subject: [PATCH] Add abiility to set replyTo in mail to form owner (#21) --- Classes/Controller/EmailController.php | 10 +++++++++- Configuration/TypoScript/setup.typoscript | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Classes/Controller/EmailController.php b/Classes/Controller/EmailController.php index e6d3df4..c20617f 100644 --- a/Classes/Controller/EmailController.php +++ b/Classes/Controller/EmailController.php @@ -334,6 +334,7 @@ public function createAction(\Slub\SlubForms\Domain\Model\Email $newEmail, array $this->sendTemplateEmail( array($newEmail->getSenderEmail() => $newEmail->getSenderName()), array($this->settings['senderEmailAddress'] => LocalizationUtility::translate('slub-forms.senderEmailName', 'slub_forms') . ' - noreply'), + array() LocalizationUtility::translate('slub-forms.senderSubject', 'slub_forms') . ' ' . $form->getTitle(), 'ConfirmEmail', array( 'email' => $newEmail, @@ -350,10 +351,15 @@ public function createAction(\Slub\SlubForms\Domain\Model\Email $newEmail, array if($this->settings['overwriteFromEmailAdressToOwner'] && strlen($this->settings['overwriteFromEmailAdressToOwner']) > 0) { $senderEmail = $this->settings['overwriteFromEmailAdressToOwner']; } + $replyto = array(); + if($this->settings['setReplyTo'] && intval($this->settings['setReplyTo']) === 1) { + $replyto = array($newEmail->getSenderEmail() => ''); + } $this->sendTemplateEmail( array($form->getRecipient() => ''), array($senderEmail => $newEmail->getSenderName()), + $replyto, LocalizationUtility::translate('tx_slubforms_domain_model_email.form', 'slub_forms') . ': ' . $form->getTitle() . ': '. $newEmail->getSenderName(). ', '. $newEmail->getSenderEmail() , 'FormEmail', array( 'email' => $newEmail, @@ -440,12 +446,13 @@ public function getSessionData($key) { * * @param array $recipient recipient of the email in the format array('recipient@domain.tld' => 'Recipient Name') * @param array $sender sender of the email in the format array('sender@domain.tld' => 'Sender Name') + * @param array $replyto replyto of the email in the format array('sender@domain.tld' => 'Sender Name') * @param string $subject subject of the email * @param string $templateName template name (UpperCamelCase) * @param array $variables variables to be passed to the Fluid view * @return boolean TRUE on success, otherwise false */ - protected function sendTemplateEmail(array $recipient, array $sender, $subject, $templateName, array $variables = array()) { + protected function sendTemplateEmail(array $recipient, array $sender, array $replyto, $subject, $templateName, array $variables = array()) { /** @var \TYPO3\CMS\Fluid\View\StandaloneView $emailViewHTML */ $emailViewHTML = $this->objectManager->get(\TYPO3\CMS\Fluid\View\StandaloneView::class); @@ -465,6 +472,7 @@ protected function sendTemplateEmail(array $recipient, array $sender, $subject, $message->setTo($recipient) ->setFrom($sender) + ->setReplyTo($replyto) ->setCharset('utf-8') ->setSubject($subject); diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index ac70b60..d5c5bc6 100644 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -15,6 +15,8 @@ plugin.tx_slubforms { overwriteFromEmailAdressToOwner = noreply@slub-dresden.de + setReplyTo = 1 + // allow sending anonymous mails #anonymEmails { # allow = 1