From aed55ee29029102bb0e053f901c954f0b4eff3b3 Mon Sep 17 00:00:00 2001
From: Torsten Oppermann <torsten@sgalinski.de>
Date: Mon, 19 Sep 2016 11:14:36 +0200
Subject: [PATCH] [TASK] Email is now rendered via fluid

---
 Classes/Service/MailTemplateService.php | 28 ++++++-------------------
 1 file changed, 6 insertions(+), 22 deletions(-)

diff --git a/Classes/Service/MailTemplateService.php b/Classes/Service/MailTemplateService.php
index d7d75c1e..8cd69282 100644
--- a/Classes/Service/MailTemplateService.php
+++ b/Classes/Service/MailTemplateService.php
@@ -85,33 +85,17 @@ class MailTemplateService {
 		$registerArray = MailTemplateService::getRegisterArray();
 		$templateEntry = $registerArray[$extensionKey][$templateKey];
 
-		$templateFileContents = file_get_contents(
-			$templateEntry['templatePath'] . $language . '.sg_mail.locallang.html'
-		);
-
-		$body = MailTemplateService::injectEmailContent($templateFileContents, $content);
+		$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
+		$emailView = $objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
+		$emailView->setTemplatePathAndFilename($templateEntry['templatePath'] . $language . '.sg_mail.locallang.html');
+		$emailView->assignMultiple($content);
+		$emailBody = $emailView->render();
 
 		$mail = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
 		$mail->setFrom($fromAddress);
 		$mail->setTo($toAddress);
 		$mail->setSubject($subject);
-		$mail->setBody($body);
+		$mail->setBody($emailBody, 'text/html');
 		$mail->send();
 	}
-
-	/**
-	 * injects content into template
-	 *
-	 * @param string $templateContent
-	 * @param array $marker
-	 * @return string
-	 */
-	private static function injectEmailContent($templateContent, array $content) {
-
-		foreach ($content as $marker => $value) {
-			str_replace('{' . $marker . '}', $value, $templateContent);
-		}
-
-		return $templateContent;
-	}
 }
-- 
GitLab