Created by
This Mächler
last modified
| /**
* sendVerificationMail
*
* @param string $subject the email subject
* @param \MMC\MmcDirectmailSubscription\Domain\Model\Address $address
* @param string $bodyTemplateFile the template file for the mail body
* @return void
*/
protected function sendVerificationMail( $subject, $address, $bodyTemplateFile ){
// make mailer instance
$mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
// setup email components
$recipients = array( $address->getEmail() => $address->getName() );
$from = array( $this->settings['fromEmail'] => $this->settings['fromName'] );
$view = $this->getStandaloneView( $bodyTemplateFile );
$view->assign( 'lang', $GLOBALS['TSFE']->lang );
$view->assign( 'sysLangUid', $GLOBALS['TSFE']->sys_language_uid );
$view->assign( 'address', $address );
$mailBody = $view->render();
// send mail
try{
$mail->setFrom( $from )
->setTo( $recipients )
->setSubject( $subject )
->setBody($mailBody, 'text/html')
->send();
} catch ( \Exception $e ){
$this->addFlashMessage('error while sending mail: '.$e->getMessage() );
}
if(! $mail->isSent())
$this->addFlashMessage('error while sending mail: mail could not be sent' );
}
/* ------------------------------------- Utility ---------------------------------------- */
protected function getStandaloneView($file) {
// create another instance of Fluid
$renderer = $this->objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
//$renderer->setFormat("html");
$renderer->setControllerContext($this->controllerContext);
// find the view-settings and set the template-files
$conf = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$renderer->setTemplatePathAndFilename(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($conf['view']['templateRootPath']) . $file);
$renderer->setLayoutRootPath(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($conf['view']['layoutRootPath']));
$renderer->setPartialRootPath(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($conf['view']['partialRootPath']));
// and return the new Fluid instance
return $renderer;
}
|
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 193 195 197 199