Initial commit
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
namespace EP\EpTheme\Service;
|
||||
|
||||
/***************************************************************
|
||||
*
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2018 Björn Fromme <[email protected]>, dreipunktnull
|
||||
*
|
||||
* 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\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
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @param ConfigurationManagerInterface $manager
|
||||
*/
|
||||
public function injectConfigurationManager(ConfigurationManagerInterface $manager)
|
||||
{
|
||||
$this->configurationManager = $manager;
|
||||
$settings = GeneralUtility::removeDotsFromTS(
|
||||
$this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
|
||||
);
|
||||
$this->settings = $settings['plugin']['tx_eptheme'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $toEmail
|
||||
* @param string $toName
|
||||
* @param string $subject
|
||||
* @param string $templateName
|
||||
* @param array $variables
|
||||
* @return bool
|
||||
*/
|
||||
public function send($toEmail, $toName, $subject, $templateName, array $variables = [])
|
||||
{
|
||||
$fromEmail = $this->settings['settings']['contactFormToEmail'];
|
||||
$fromName = $this->settings['settings']['contactFormToName'];
|
||||
|
||||
/** @var MailMessage $message */
|
||||
$message = GeneralUtility::makeInstance(MailMessage::class);
|
||||
$message
|
||||
->setTo([$toEmail => $toName])
|
||||
->setFrom([$fromEmail => $fromName])
|
||||
->setSubject($subject)
|
||||
;
|
||||
|
||||
$view = $this->getView($templateName);
|
||||
$view->assignMultiple($variables);
|
||||
$message->setBody($view->render(), 'text/html');
|
||||
|
||||
$message->send();
|
||||
|
||||
return $message->isSent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @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