Implement fluidemail
This commit is contained in:
@@ -26,34 +26,25 @@ namespace EP\EpProducts\Service;
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use TYPO3\CMS\Core\Mail\MailMessage;
|
||||
use TYPO3\CMS\Core\Mail\FluidEmail;
|
||||
use TYPO3\CMS\Core\Mail\Mailer;
|
||||
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
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @param ConfigurationManagerInterface $manager
|
||||
*/
|
||||
public function injectConfigurationManager(ConfigurationManagerInterface $manager)
|
||||
public function __construct(ConfigurationManagerInterface $manager)
|
||||
{
|
||||
$this->configurationManager = $manager;
|
||||
$settings = GeneralUtility::removeDotsFromTS(
|
||||
$this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
|
||||
$manager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
|
||||
);
|
||||
$this->settings = $settings['plugin']['tx_eptheme'];
|
||||
}
|
||||
@@ -67,40 +58,17 @@ class EmailService implements SingletonInterface
|
||||
{
|
||||
$resolvedOptions = $this->resolveOptions($options);
|
||||
|
||||
/** @var MailMessage $message */
|
||||
$message = GeneralUtility::makeInstance(MailMessage::class);
|
||||
$message
|
||||
->setTo([$resolvedOptions['toEmail'] => $resolvedOptions['toName']])
|
||||
->setFrom([$resolvedOptions['fromEmail'] => $resolvedOptions['fromName']])
|
||||
->setSubject($resolvedOptions['subject'])
|
||||
/** @var FluidEmail $email */
|
||||
$email = GeneralUtility::makeInstance(FluidEmail::class);
|
||||
$email
|
||||
->to(new Address($resolvedOptions['toEmail'], $resolvedOptions['toName']))
|
||||
->from(new Address($resolvedOptions['fromEmail'], $resolvedOptions['fromName']))
|
||||
->subject($resolvedOptions['subject'])
|
||||
->setTemplate($resolvedOptions['templateName'])
|
||||
->assignMultiple($variables)
|
||||
;
|
||||
|
||||
$view = $this->getView($resolvedOptions['templateName']);
|
||||
$view->assignMultiple($variables);
|
||||
$message->setBody($view->render(), 'text/html');
|
||||
|
||||
return $message->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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->setTemplateRootPaths($this->settings['view']['templateRootPaths']);
|
||||
$view->setLayoutRootPaths($this->settings['view']['layoutRootPaths']);
|
||||
$view->setPartialRootPaths($this->settings['view']['partialRootPaths']);
|
||||
|
||||
$template = GeneralUtility::getFileAbsFileName('EXT:ep_theme/Resources/Private/Templates/Email/'.$templateName.'.'.$format);
|
||||
$view->setTemplatePathAndFilename($template);
|
||||
|
||||
return $view;
|
||||
GeneralUtility::makeInstance(Mailer::class)->send($email);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -73,7 +73,7 @@ class AjaxFormController extends ActionController
|
||||
$this->settings['contactFormToEmail'],
|
||||
$this->settings['contactFormToName'],
|
||||
'Kontaktformular E&P Reisen',
|
||||
'Email/ContactForm',
|
||||
'ContactForm',
|
||||
[ 'contactForm' => $contactForm ]
|
||||
);
|
||||
|
||||
|
||||
@@ -26,33 +26,24 @@ namespace EP\EpTheme\Service;
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use TYPO3\CMS\Core\Mail\MailMessage;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use TYPO3\CMS\Core\Mail\FluidEmail;
|
||||
use TYPO3\CMS\Core\Mail\Mailer;
|
||||
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
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @param ConfigurationManagerInterface $manager
|
||||
*/
|
||||
public function injectConfigurationManager(ConfigurationManagerInterface $manager)
|
||||
public function __construct(ConfigurationManagerInterface $manager)
|
||||
{
|
||||
$this->configurationManager = $manager;
|
||||
$settings = GeneralUtility::removeDotsFromTS(
|
||||
$this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
|
||||
$manager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
|
||||
);
|
||||
$this->settings = $settings['plugin']['tx_eptheme'];
|
||||
}
|
||||
@@ -63,72 +54,49 @@ class EmailService implements SingletonInterface
|
||||
* @param string $subject
|
||||
* @param string $templateName
|
||||
* @param array $variables
|
||||
* @return bool
|
||||
*/
|
||||
public function send($toEmail, $toName, $subject, $templateName, array $variables = [])
|
||||
{
|
||||
/** @var Mailer $mailer */
|
||||
$mailer = GeneralUtility::makeInstance(Mailer::class);
|
||||
$fromEmail = $this->settings['settings']['contactFormToEmail'];
|
||||
$fromName = $this->settings['settings']['contactFormToName'];
|
||||
$enableAutoreply = $this->settings['settings']['enableContactFormAutoreply'];
|
||||
$enableAutoreply = (bool)$this->settings['settings']['enableContactFormAutoreply'];
|
||||
$autoreplySubject = $this->settings['settings']['contactFormAutoreplySubject'];
|
||||
|
||||
/** @var MailMessage $message */
|
||||
$message = GeneralUtility::makeInstance(MailMessage::class);
|
||||
/** @var FluidEmail $message */
|
||||
$message = GeneralUtility::makeInstance(FluidEmail::class);
|
||||
$message
|
||||
->setTo([$toEmail => $toName])
|
||||
->setFrom([$fromEmail => $fromName])
|
||||
->setSubject($subject)
|
||||
->to(new Address($toEmail, $toName))
|
||||
->from(new Address($fromEmail, $fromName))
|
||||
->format('html')
|
||||
->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($message);
|
||||
|
||||
if ($enableAutoreply) {
|
||||
$contactForm = $variables['contactForm'];
|
||||
$toEmail = $contactForm->getEmail();
|
||||
$toName = $contactForm->getName();
|
||||
$templateName = 'Email/Autoreply';
|
||||
$templateName = 'Autoreply';
|
||||
|
||||
/** @var MailMessage $message */
|
||||
$message = GeneralUtility::makeInstance(MailMessage::class);
|
||||
/** @var FluidEmail $message */
|
||||
$message = GeneralUtility::makeInstance(FluidEmail::class);
|
||||
$message
|
||||
->setTo([$toEmail => $toName])
|
||||
->setFrom([$fromEmail => $fromName])
|
||||
->setSubject($autoreplySubject)
|
||||
->to(new Address($toEmail, $toName))
|
||||
->from(new Address($fromEmail, $fromName))
|
||||
->format('html')
|
||||
->subject($autoreplySubject)
|
||||
->setTemplate($templateName)
|
||||
->assignMultiple($variables)
|
||||
;
|
||||
|
||||
$view = $this->getView($templateName);
|
||||
$view->assignMultiple($variables);
|
||||
$message->setBody($view->render(), 'text/html');
|
||||
|
||||
$autoreplySent = $message->send();
|
||||
$mailer->send($message);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers"
|
||||
xmlns:f="http://typo3.org/ns/fluid/ViewHelpers">
|
||||
|
||||
<f:layout name="Email/Default"/>
|
||||
<f:layout name="Default"/>
|
||||
|
||||
<f:section name="Main">
|
||||
<p>Sehr geehrte Damen und Herren,</p>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers"
|
||||
xmlns:f="http://typo3.org/ns/fluid/ViewHelpers">
|
||||
|
||||
<f:layout name="Email/Default"/>
|
||||
<f:layout name="Default"/>
|
||||
|
||||
<f:section name="Main">
|
||||
<h1>Anfrage E&P Reisen vom <f:format.date date="now" format="d.m.y" /></h1>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers"
|
||||
xmlns:f="http://typo3.org/ns/fluid/ViewHelpers">
|
||||
|
||||
<f:layout name="Email/Default"/>
|
||||
<f:layout name="Default"/>
|
||||
|
||||
<f:section name="Main">
|
||||
<h1>Anfrage Gruppenhaus vom <f:format.date date="now" format="d.m.y" /></h1>
|
||||
|
||||
@@ -22,6 +22,9 @@ $GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'] = 'tx_eptheme_slides';
|
||||
$GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets']['default'] = 'EXT:ep_theme/Configuration/RTE/Default.yaml';
|
||||
$GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets']['ep-reisen'] = 'EXT:ep_theme/Configuration/RTE/Default.yaml';
|
||||
|
||||
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['layoutRootPaths'][700] = 'EXT:ep_theme/Resources/Private/Layouts/Email/';
|
||||
$GLOBALS['TYPO3_CONF_VARS']['MAIL']['templateRootPaths'][700] = 'EXT:ep_theme/Resources/Private/Templates/Email/';
|
||||
|
||||
$metaTagManagerRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry::class);
|
||||
$metaTagManagerRegistry->registerManager(
|
||||
'ep_opengraph',
|
||||
|
||||
Reference in New Issue
Block a user