Extbase - E-Mail / MailMessage

Aus Wikizone
Version vom 29. Juli 2015, 13:03 Uhr von 37.49.33.84 (Diskussion) (Die Seite wurde neu angelegt: „<syntaxhighlight lang="php"> protected function sendTemplateEmail(array $recipient, array $sender, $subject, $templateName, array $variables = array()) { /*…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche
	protected function sendTemplateEmail(array $recipient, array $sender, $subject, $templateName, array $variables = array()) {
		/** @var \TYPO3\CMS\Fluid\View\StandaloneView $emailView */
		$emailView = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
 
		$extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(
			\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
		$templateRootPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName(
			$extbaseFrameworkConfiguration['view']['templateRootPath']);
		$templatePathAndFilename = $templateRootPath . 'Email/' . $templateName . '.html';
		$emailView->setTemplatePathAndFilename($templatePathAndFilename);
		$emailView->assignMultiple($variables);
		$emailBody = $emailView->render();
 
		/** @var $message \TYPO3\CMS\Core\Mail\MailMessage */
		$message = $this->objectManager->get('TYPO3\\CMS\\Core\\Mail\\MailMessage');
		$message->setTo($recipient)
			->setFrom($sender)
			->setSubject($subject);
 
		// Possible attachments here
		//foreach ($attachments as $attachment) {
		//	$message->attach(\Swift_Attachment::fromPath($attachment));
		//}
 
		// Plain text example
		$message->setBody($emailBody, 'text/plain');
		// HTML Email
		#$message->setBody($emailBody, 'text/html');
		$message->send();
		//print DebuggerUtility::var_dump( $message );		
		return $message->isSent();
	}