Implement fluidemail
This commit is contained in:
@@ -64,7 +64,7 @@ class AjaxFormController extends ActionController
|
||||
'toEmail' => $this->settings['inquiryToEmail'],
|
||||
'toName' => $this->settings['inquiryToName'],
|
||||
'subject' => 'Anfrage E&P Events',
|
||||
'templateName' => 'Email/Inquiry',
|
||||
'templateName' => 'Inquiry',
|
||||
'variables' => [ 'inquiry' => $inquiry ]
|
||||
]);
|
||||
return json_encode($response);
|
||||
@@ -82,7 +82,7 @@ class AjaxFormController extends ActionController
|
||||
'toEmail' => $this->settings['inquiryToEmail'],
|
||||
'toName' => $this->settings['inquiryToName'],
|
||||
'subject' => 'Anfrage E&P Events',
|
||||
'templateName' => 'Email/Configurator',
|
||||
'templateName' => 'Configurator',
|
||||
'variables' => [
|
||||
'inquiry' => $inquiry,
|
||||
'config' => $this->configurationService->getConfiguratorConfig(),
|
||||
|
||||
@@ -28,20 +28,16 @@ namespace EP\EpEvents\Service;
|
||||
***************************************************************/
|
||||
|
||||
use EP\EpEvents\Domain\Model\Inquiry;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use TYPO3\CMS\Core\Mail\FluidEmail;
|
||||
use TYPO3\CMS\Core\Mail\Mailer;
|
||||
use TYPO3\CMS\Core\Mail\MailMessage;
|
||||
use TYPO3\CMS\Core\SingletonInterface;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||
use TYPO3\CMS\Fluid\View\StandaloneView;
|
||||
|
||||
class EmailService implements SingletonInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ConfigurationManagerInterface
|
||||
*/
|
||||
protected $configurationManager;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@@ -52,9 +48,8 @@ class EmailService implements SingletonInterface
|
||||
*/
|
||||
public function __construct(ConfigurationManagerInterface $configurationManager)
|
||||
{
|
||||
$this->configurationManager = $configurationManager;
|
||||
$settings = GeneralUtility::removeDotsFromTS(
|
||||
$this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
|
||||
$configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
|
||||
);
|
||||
$this->settings = $settings['plugin']['tx_epevents'];
|
||||
}
|
||||
@@ -66,6 +61,9 @@ class EmailService implements SingletonInterface
|
||||
*/
|
||||
public function send(array $options)
|
||||
{
|
||||
/** @var Mailer $mailer */
|
||||
$mailer = GeneralUtility::makeInstance(Mailer::class);
|
||||
|
||||
$fromEmail = $this->settings['settings']['inquiryToEmail'];
|
||||
$fromName = $this->settings['settings']['inquiryToName'];
|
||||
$enableAutoreply = $this->settings['settings']['enableContactFormAutoreply'];
|
||||
@@ -77,20 +75,17 @@ class EmailService implements SingletonInterface
|
||||
$templateName = $options['templateName'];
|
||||
$variables = $options['variables'];
|
||||
|
||||
/** @var MailMessage $message */
|
||||
$message = GeneralUtility::makeInstance(MailMessage::class);
|
||||
$message
|
||||
->setTo([$toEmail => $toName])
|
||||
->setFrom([$fromEmail => $fromName])
|
||||
->setSubject($subject)
|
||||
/** @var FluidEmail $email */
|
||||
$email = GeneralUtility::makeInstance(FluidEmail::class);
|
||||
$email
|
||||
->to(new Address($toEmail, $toName))
|
||||
->from(new Address($fromEmail, $fromName))
|
||||
->subject($subject)
|
||||
->setTemplate($templateName)
|
||||
->assignMultiple($variables)
|
||||
;
|
||||
|
||||
$view = $this->getView($templateName);
|
||||
$view->assignMultiple($variables);
|
||||
$message->setBody($view->render(), 'text/html');
|
||||
|
||||
$messageSent = $message->send();
|
||||
$autoreplySent = false;
|
||||
$mailer->send($email);
|
||||
|
||||
if ($enableAutoreply) {
|
||||
/** @var Inquiry $inquiry */
|
||||
@@ -99,42 +94,19 @@ class EmailService implements SingletonInterface
|
||||
$toName = $inquiry->getName();
|
||||
$templateName = 'Email/Autoreply';
|
||||
|
||||
/** @var MailMessage $message */
|
||||
$message = GeneralUtility::makeInstance(MailMessage::class);
|
||||
$message
|
||||
->setTo([$toEmail => $toName])
|
||||
->setFrom([$fromEmail => $fromName])
|
||||
->setSubject($autoreplySubject)
|
||||
/** @var FluidEmail $email */
|
||||
$email = GeneralUtility::makeInstance(MailMessage::class);
|
||||
$email
|
||||
->to(new Address($toEmail, $toName))
|
||||
->from(new Address($fromEmail, $fromName))
|
||||
->subject($autoreplySubject)
|
||||
->setTemplate($templateName)
|
||||
->assignMultiple($variables)
|
||||
;
|
||||
|
||||
$view = $this->getView($templateName);
|
||||
$view->assignMultiple($variables);
|
||||
$message->setBody($view->render(), 'text/html');
|
||||
|
||||
$autoreplySent = $message->send();
|
||||
$mailer->send($email);
|
||||
}
|
||||
|
||||
return $messageSent && $autoreplySent;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $templateName
|
||||
* @param string $format
|
||||
* @return StandaloneView
|
||||
*/
|
||||
protected function getView($templateName, $format = 'html')
|
||||
{
|
||||
/** @var StandaloneView $view */
|
||||
$view = GeneralUtility::makeInstance(StandaloneView::class);
|
||||
$view->setFormat($format);
|
||||
$view->getRequest()->setControllerExtensionName('ep_events');
|
||||
|
||||
$view->setTemplateRootPaths($this->settings['view']['templateRootPaths']);
|
||||
$view->setLayoutRootPaths($this->settings['view']['layoutRootPaths']);
|
||||
$view->setPartialRootPaths($this->settings['view']['partialRootPaths']);
|
||||
$view->setTemplate($templateName);
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user