[TYPO3-german] Template-Email aus custom Form-Handler-Finischer versenden

Nicolas Puente nicolas.puente at lgb-rlp.de
Thu Nov 27 13:50:53 CET 2014


Hallo,

ich habe diese Funktion bei mir im eine eigene Extension benutzt und so 
funktioniert!!


/**
      * @param array $recipient recipient of the email in the format 
array('recipient at domain.tld' => 'Recipient Name')
      * @param array $sender sender of the email in the format 
array('sender at domain.tld' => 'Sender Name')
      * @param string $subject subject of the email
      * @param string $templateName template name (UpperCamelCase)
      * @param array $variables variables to be passed to the Fluid view
      * @return boolean TRUE on success, otherwise false
     */
     protected function sendTemplateEmail(array $recipient, array 
$sender, $subject, $templateName, array $variables = array()) {
         //$currentContentObject = 
$this->configurationManager->getContentObject()->data;
         /** @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']);


         # Mailseden = überschreiben mit de korrekte Dir!!!!
         $templatePathAndFilename = $templateRootPath . 'Mailseden/' . 
$templateName . '.html';

$this->view->setTemplatePathAndFilename($templatePathAndFilename);

         $this->view->assignMultiple($variables);
         $emailBody = $this->view->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();
         return $message->isSent();
     }


$theReturn = $this->sendTemplateEmail(array('nicolas.puente at lgb-rlp.de' 
=> 'Recipient Name'), array('nicolas.puente at lgb-rlp.de' => 'Sender 
Name'), 'Email Subject', 'List', array('someVariable' => 'Foo Bar'));

Viele Grüße.

Nicolas


More information about the TYPO3-german mailing list