/** * Compile the newsletter and send it * * @param Email $objEmail * @param Database\Result|object $objNewsletter * @param array $arrRecipient * @param string $text * @param string $html * @param string $css * * @return string */ protected function sendNewsletter(Email $objEmail, Database\Result $objNewsletter, $arrRecipient, $text, $html, $css = null) { // Prepare the text content $objEmail->text = \StringUtil::parseSimpleTokens($text, $arrRecipient); if (!$objNewsletter->sendText) { // Default template if ($objNewsletter->template == '') { $objNewsletter->template = 'mail_default'; } /** @var BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate($objNewsletter->template); $objTemplate->setData($objNewsletter->row()); $objTemplate->title = $objNewsletter->subject; $objTemplate->body = \StringUtil::parseSimpleTokens($html, $arrRecipient); $objTemplate->charset = \Config::get('characterSet'); $objTemplate->recipient = $arrRecipient['email']; // Deprecated since Contao 4.0, to be removed in Contao 5.0 $objTemplate->css = $css; // Parse template $objEmail->html = $objTemplate->parse(); $objEmail->imageDir = TL_ROOT . '/'; } // Deactivate invalid addresses try { $objEmail->sendTo($arrRecipient['email']); } catch (\Swift_RfcComplianceException $e) { $_SESSION['REJECTED_RECIPIENTS'][] = $arrRecipient['email']; } // Rejected recipients if ($objEmail->hasFailures()) { $_SESSION['REJECTED_RECIPIENTS'][] = $arrRecipient['email']; } // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['sendNewsletter']) && is_array($GLOBALS['TL_HOOKS']['sendNewsletter'])) { foreach ($GLOBALS['TL_HOOKS']['sendNewsletter'] as $callback) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($objEmail, $objNewsletter, $arrRecipient, $text, $html); } } }
/** * @param $strRecipient * @return bool */ public function sendTo($strRecipient) { if (!$this->strType) { return false; } $objEmail = new ContaoEmail(); $objEmail->from = $GLOBALS['TL_CONFIG']['emailFrom']; $strEmailFromName = Translator::translateValue($GLOBALS['TL_CONFIG']['emailFromName'], $this->strForceLanguage); // Add sender name if ($strEmailFromName != '') { $objEmail->fromName = $strEmailFromName; } $strSubject = $this->getContent('subject'); $strContent = $this->getContent(); $objEmail->embedImages = true; $objEmail->imageDir = TL_ROOT . '/'; $objEmail->subject = $strSubject; // Prepare html template $objTemplate = new BackendTemplate($this->getEmailTemplate()); $objTemplate->title = $strSubject; $objTemplate->body = $strContent; $objTemplate->charset = $GLOBALS['TL_CONFIG']['characterSet']; $objTemplate->css = ''; $objTemplate->recipient = $strRecipient; // Parse html template $objEmail->html = $objTemplate->parse(); // Send email try { $objEmail->sendTo($strRecipient); } catch (\Swift_RfcComplianceException $e) { return false; } // Rejected recipients if ($objEmail->hasFailures()) { return false; } return true; }