Ejemplo n.º 1
0
 public static function alternativeMultipartForTemplate($oTemplate, $sAlternative = null, $sCharset = null, $aTextifyMethods = 'markdown')
 {
     $sContent = $oTemplate->render();
     if ($sCharset === null) {
         $sCharset = $oTemplate->getCharset();
     }
     if ($sAlternative === null) {
         $sAlternative = $sContent;
     }
     if ($aTextifyMethods !== null) {
         if (!is_array($aTextifyMethods)) {
             $aTextifyMethods = explode('-', $aTextifyMethods);
         }
         foreach ($aTextifyMethods as $sTextfyMethod) {
             if ($sTextfyMethod === 'markdown') {
                 require_once 'markdownify/Markdownify_Extra.php';
                 $oMarkdownify = new Markdownify_Extra(false, false, false);
                 $sAlternative = $oMarkdownify->parseString($sAlternative);
             } else {
                 if ($sTextfyMethod === 'strip_tags') {
                     $sAlternative = strip_tags($sAlternative, '<' . implode('><', self::$ALLOWED_TAGS) . '>');
                 } else {
                     if ($sTextfyMethod === 'strip_tags/full') {
                         $sAlternative = strip_tags($sAlternative);
                     } else {
                         if ($sTextfyMethod === 'purify') {
                             require_once 'htmlpurifier/HTMLPurifier.standalone.php';
                             $oPurifierConfig = HTMLPurifier_Config::createDefault();
                             $sCacheDir = MAIN_DIR . '/' . DIRNAME_GENERATED . '/' . DIRNAME_CACHES . '/purifier';
                             if (!file_exists($sCacheDir)) {
                                 mkdir($sCacheDir);
                             }
                             $oPurifierConfig->set('Cache.SerializerPath', $sCacheDir);
                             $oPurifierConfig->set('AutoFormat.AutoParagraph', true);
                             $oPurifierConfig->set('HTML.AllowedElements', self::$ALLOWED_TAGS);
                             $oPurifier = new HTMLPurifier($oPurifierConfig);
                             $sAlternative = $oPurifier->purify($sAlternative);
                         }
                     }
                 }
             }
         }
     }
     $oMimeTree = new MIMEMultipart('alternative');
     $oMimeTree->addPart(MIMELeaf::leafWithText($sAlternative, '8bit', $sCharset));
     $oMimeTree->addPart(new MIMELeaf($sContent, 'text/html', '8bit', $sCharset));
     return $oMimeTree;
 }
Ejemplo n.º 2
0
 public function send()
 {
     $aRecipients = array();
     foreach ($this->aRecipients as $sAddress => $sName) {
         $aRecipients[] = $this->getAddressToken($sName, $sAddress);
     }
     $sRecipients = implode(', ', $aRecipients);
     if ($this->oContent instanceof Template) {
         $this->oContent = MIMELeaf::leafWithTemplate($this->oContent, $this->sMimeType, '8bit', null, null, $this->sCharset);
     }
     foreach ($this->aCarbonCopyRecipients as $sAddress => $sName) {
         $this->oContent->addToHeader("Cc", $this->getAddressToken($sName, $sAddress));
     }
     foreach ($this->aBlindCarbonCopyRecipients as $sAddress => $sName) {
         $this->oContent->addToHeader("Bcc", $this->getAddressToken($sName, $sAddress));
     }
     if ($this->sReplyTo !== null) {
         $this->oContent->setHeader("Reply-To", $this->sReplyTo);
     }
     $this->oContent->setHeader('From', $this->getAddressToken($this->sSenderName, $this->sSenderAddress));
     $sSubject = '=?' . Settings::getSetting("encoding", "db", "utf-8") . '?B?' . base64_encode($this->sSubject) . '?=';
     $bResult = $this->sendMail($sRecipients, $sSubject, $this->oContent->getBody(), $this->oContent->getHeaderString());
     if ($bResult === false) {
         throw new Exception("Error in EMail->send(): E-Mail was not accepted for delivery: " . $sRecipients);
     }
 }