Implement contact form autoreply for epevents
This commit is contained in:
@@ -56,13 +56,13 @@ class AjaxFormController extends ActionController
|
||||
public function processInquiryFormAction(Inquiry $inquiry)
|
||||
{
|
||||
$response['status'] = 'ok';
|
||||
$this->emailService->send(
|
||||
$this->settings['inquiryToEmail'],
|
||||
$this->settings['inquiryToName'],
|
||||
'Anfrage E&P Events',
|
||||
'Email/Inquiry',
|
||||
[ 'inquiry' => $inquiry ]
|
||||
);
|
||||
$this->emailService->send([
|
||||
'toEmail' => $this->settings['inquiryToEmail'],
|
||||
'toName' => $this->settings['inquiryToName'],
|
||||
'subject' => 'Anfrage E&P Events',
|
||||
'templateName' => 'Email/Inquiry',
|
||||
'variables' => [ 'inquiry' => $inquiry ]
|
||||
]);
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
@@ -74,13 +74,13 @@ class AjaxFormController extends ActionController
|
||||
public function processConfiguratorFormAction(Inquiry $inquiry)
|
||||
{
|
||||
$response['status'] = 'ok';
|
||||
$this->emailService->send(
|
||||
$this->settings['inquiryToEmail'],
|
||||
$this->settings['inquiryToName'],
|
||||
'Anfrage E&P Events',
|
||||
'Email/Configurator',
|
||||
[ 'inquiry' => $inquiry ]
|
||||
);
|
||||
$this->emailService->send([
|
||||
'toEmail' => $this->settings['inquiryToEmail'],
|
||||
'toName' => $this->settings['inquiryToName'],
|
||||
'subject' => 'Anfrage E&P Events',
|
||||
'templateName' => 'Email/Configurator',
|
||||
'variables' => [ 'inquiry' => $inquiry ]
|
||||
]);
|
||||
return json_encode($response);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace EP\EpEvents\Service;
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use EP\EpEvents\Domain\Model\Inquiry;
|
||||
use TYPO3\CMS\Core\Mail\MailMessage;
|
||||
use TYPO3\CMS\Core\SingletonInterface;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
@@ -59,17 +60,22 @@ class EmailService implements SingletonInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $toEmail
|
||||
* @param string $toName
|
||||
* @param string $subject
|
||||
* @param string $templateName
|
||||
* @param array $options
|
||||
* @param array $variables
|
||||
* @return bool
|
||||
*/
|
||||
public function send($toEmail, $toName, $subject, $templateName, array $variables = [])
|
||||
public function send(array $options)
|
||||
{
|
||||
$fromEmail = $this->settings['settings']['inquiryToEmail'];
|
||||
$fromName = $this->settings['settings']['inquiryToName'];
|
||||
$enableAutoreply = $this->settings['settings']['enableContactFormAutoreply'];
|
||||
$autoreplySubject = $this->settings['settings']['contactFormAutoreplySubject'];
|
||||
|
||||
$toEmail = $options['toEmail'];
|
||||
$toName = $options['toName'];
|
||||
$subject = $options['subject'];
|
||||
$templateName = $options['templateName'];
|
||||
$variables = $options['variables'];
|
||||
|
||||
/** @var MailMessage $message */
|
||||
$message = GeneralUtility::makeInstance(MailMessage::class);
|
||||
@@ -83,9 +89,32 @@ class EmailService implements SingletonInterface
|
||||
$view->assignMultiple($variables);
|
||||
$message->setBody($view->render(), 'text/html');
|
||||
|
||||
$message->send();
|
||||
$messageSent = $message->send();
|
||||
$autoreplySent = false;
|
||||
|
||||
return $message->isSent();
|
||||
if ($enableAutoreply) {
|
||||
/** @var Inquiry $inquiry */
|
||||
$inquiry = $variables['inquiry'];
|
||||
$toEmail = $inquiry->getEmail();
|
||||
$toName = $inquiry->getName();
|
||||
$templateName = 'Email/Autoreply';
|
||||
|
||||
/** @var MailMessage $message */
|
||||
$message = GeneralUtility::makeInstance(MailMessage::class);
|
||||
$message
|
||||
->setTo([$toEmail => $toName])
|
||||
->setFrom([$fromEmail => $fromName])
|
||||
->setSubject($autoreplySubject)
|
||||
;
|
||||
|
||||
$view = $this->getView($templateName);
|
||||
$view->assignMultiple($variables);
|
||||
$message->setBody($view->render(), 'text/html');
|
||||
|
||||
$autoreplySent = $message->send();
|
||||
}
|
||||
|
||||
return $messageSent && $autoreplySent;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user