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