<?php namespace SGalinski\SgMail\Service; /*************************************************************** * Copyright notice * * (c) sgalinski Internet Services (https://www.sgalinski.de) * * All rights reserved * * This script is part of the TYPO3 project. The TYPO3 project is * free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * The GNU General Public License can be found at * http://www.gnu.org/copyleft/gpl.html. * * This script is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This copyright notice MUST APPEAR in all copies of the script! ***************************************************************/ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Object\ObjectManager; use Typoheads\Formhandler\Finisher\AbstractFinisher; /** * Class FormhandlerFinisherService * * @package SGalinski\SgMail\Service */ class FormhandlerFinisherService extends AbstractFinisher { /** * Hook into Formhandler, sets config and form input * gets called in the finisher of the typoscript * redirects to process() function * * @param array $formInput * @param array $settings */ public function init($formInput, $settings) { foreach ($formInput as &$userInput) { // if value is an array, iterate over array values if (is_array($userInput)) { foreach ($userInput as &$input) { $input = GeneralUtility::removeXSS($input); } continue; } $userInput = GeneralUtility::removeXSS($userInput); } $this->gp = $formInput; $this->settings = $settings; } /** * Redirect Formhandler input to send Email Function * Needed to hook into Formhandler * * @return array $gp * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException * @throws \InvalidArgumentException */ public function process() { if (!isset($this->settings['to_address'])) { $toAddressField = $this->settings['to_address_field']; $toAddress = $this->gp[$toAddressField]; } else { $toAddress = $this->settings['to_address']; } $objectManager = GeneralUtility::makeInstance(ObjectManager::class); /** @var \SGalinski\SgMail\Service\MailTemplateService $mailTemplateService */ $mailTemplateService = $objectManager->get(MailTemplateService::class); $mailTemplateService->setToAddresses($toAddress); $mailTemplateService->setLanguage($GLOBALS['TSFE']->config['config']['language']); $mailTemplateService->setFromAddress($this->settings['from_address']); $mailTemplateService->setTemplateName($this->settings['template_key']); $mailTemplateService->setExtensionKey($this->settings['extension_key']); $mailTemplateService->setMarkers($this->gp); $mailTemplateService->setIgnoreMailQueue($this->settings['ignore_mail_queue'] == TRUE); $mailTemplateService->sendEmail(); return $this->gp; } }