public function sendEmail($from, $to, $cc, $subject, $body, $attachmentFilename)
 {
     $message = new Message();
     $message->setFrom($from);
     $message->setTo($to);
     $message->setCc($cc);
     $message->setSubject($subject);
     $mimeMessage = new \Zend\Mime\Message();
     $part = new \Zend\Mime\Part($body);
     $part->setType(Mime::TYPE_TEXT);
     $part->setCharset('UTF-8');
     $mimeMessage->addPart($part);
     $part = new \Zend\Mime\Part('<p>' . $body . '<p>');
     $part->setType(Mime::TYPE_HTML);
     $part->setCharset('UTF-8');
     $mimeMessage->addPart($part);
     $part = new \Zend\Mime\Part($body);
     $part->setType(Mime::TYPE_OCTETSTREAM);
     $part->setEncoding(Mime::ENCODING_BASE64);
     $part->setFileName($attachmentFilename);
     $part->setDisposition(Mime::DISPOSITION_ATTACHMENT);
     $mimeMessage->addPart($part);
     $message->setBody($mimeMessage);
     $this->transport->send($message);
     $this->debugSection('ZendMailer', $subject . ' ' . $from . ' -> ' . $to);
 }
Ejemplo n.º 2
0
 private function get_edition_mail($editionId, $target, $is_html = null, $replyTo = null, $sendFrom = null)
 {
     global $prefs, $base_url;
     static $mailcache = array();
     if (!isset($mailcache[$editionId])) {
         $tikilib = TikiLib::lib('tiki');
         $headerlib = TikiLib::lib('header');
         $info = $this->get_edition($editionId);
         $nl_info = $this->get_newsletter($info['nlId']);
         // build the html
         $beginHtml = '<body class="tiki_newsletters"><div id="tiki-center" class="clearfix content"><div class="wikitext">';
         $endHtml = '</div></div></body>';
         if ($is_html === null) {
             $is_html = $info['wysiwyg'] === 'y' && $prefs['wysiwyg_htmltowiki'] !== 'y';
             // parse as html if wysiwyg and not htmltowiki
         } else {
             $is_html = !empty($is_html);
         }
         if (stristr($info['data'], '<body') === false) {
             $html = "<html>{$beginHtml}" . $tikilib->parse_data($info['data'], array('absolute_links' => true, 'suppress_icons' => true, 'is_html' => $is_html)) . "{$endHtml}</html>";
         } else {
             $html = str_ireplace('<body>', $beginHtml, $info['data']);
             $html = str_ireplace('</body>', $endHtml, $html);
         }
         if ($nl_info['allowArticleClip'] == 'y' && $nl_info['autoArticleClip'] == 'y') {
             $articleClip = $this->clip_articles($nl_info['nlId']);
             $txtArticleClip = $this->generateTxtVersion($articleClip);
             $info['datatxt'] = str_replace('~~~articleclip~~~', $txtArticleClip, $info['datatxt']);
             $html = str_replace('~~~articleclip~~~', $articleClip, $html);
             if ($articleClip == '<div class="articleclip"></div>' && $nl_info['emptyClipBlocksSend'] == 'y') {
                 return '';
             }
         }
         if (stristr($html, '<base') === false) {
             if (stristr($html, '<head') === false) {
                 $themelib = TikiLib::lib('theme');
                 $news_cssfile = $themelib->get_theme_path($prefs['theme'], '', 'newsletter.css');
                 $news_cssfile_option = $themelib->get_theme_path($prefs['theme'], $prefs['theme_option'], 'newsletter.css');
                 $news_css = '';
                 if (!empty($news_cssfile)) {
                     $news_css .= $headerlib->minify_css($news_cssfile);
                 }
                 if (!empty($news_cssfile_option) && $news_cssfile_option !== $news_cssfile) {
                     $news_css .= $headerlib->minify_css($news_cssfile_option);
                 }
                 if (empty($news_css)) {
                     $news_css = $headerlib->get_all_css_content();
                 }
                 $news_head = "<html><head><base href=\"{$base_url}\" /><style type=\"text/css\">{$news_css}</style></head>";
                 $html = str_ireplace('<html>', $news_head, $html);
             } else {
                 $html = str_ireplace('<head>', "<head><base href=\"{$base_url}\" />", $html);
             }
         }
         $info['files'] = $this->get_edition_files($editionId);
         include_once 'lib/mail/maillib.php';
         /* @var Zend\Mail\Message $zmail */
         $zmail = tiki_get_admin_mail();
         $emailMimeParts = array();
         if (!empty($replyTo)) {
             $zmail->setReplyTo($replyTo);
         }
         if (!empty($sendFrom)) {
             $zmail->setFrom($sendFrom);
             $zmail->setSender($sendFrom);
         }
         foreach ($info['files'] as $f) {
             $fpath = isset($f['path']) ? $f['path'] : $prefs['tmpDir'] . '/newsletterfile-' . $f['filename'];
             $att = new Zend\Mime\Part(file_get_contents($fpath));
             $att->filename = $f['name'];
             $att->type = $f['type'];
             $att->encoding = Zend\Mime\Mime::ENCODING_BASE64;
             $emailMimeParts[] = $att;
         }
         $zmail->setSubject($info['subject']);
         $mailcache[$editionId] = array('zmail' => $zmail, 'text' => $info['datatxt'], 'html' => $html, 'unsubMsg' => $nl_info['unsubMsg'], 'nlId' => $nl_info['nlId']);
     }
     $cache = $mailcache[$editionId];
     $html = $cache['html'];
     $unsubmsg = '';
     if ($cache["unsubMsg"] == 'y' && !empty($target["code"])) {
         $unsubmsg = $this->get_unsub_msg($cache["nlId"], $target['email'], $target['language'], $target["code"], $target['user']);
         if (stristr($html, '</body>') === false) {
             $html .= $unsubmsg;
         } else {
             $html = str_replace("</body>", nl2br($unsubmsg) . "</body>", $html);
         }
     }
     $zmail = $cache['zmail'];
     $textPart = new Zend\Mime\Part($cache['text'] . strip_tags($unsubmsg));
     $textPart->setCharset('UTF-8');
     $textPart->setType(Zend\Mime\Mime::TYPE_TEXT);
     $emailMimeParts[] = $textPart;
     $htmlPart = new Zend\Mime\Part($html);
     $htmlPart->setCharset('UTF-8');
     $htmlPart->setType(Zend\Mime\Mime::TYPE_HTML);
     $emailMimeParts[] = $htmlPart;
     $emailBody = new \Zend\Mime\Message();
     $emailBody->setParts($emailMimeParts);
     $zmail->setBody($emailBody);
     $zmail->setEncoding('UTF-8');
     $zmail->getHeaders()->removeHeader('to');
     $zmail->getHeaders()->removeHeader('cc');
     $zmail->getHeaders()->removeHeader('bcc');
     $zmail->addTo($target['email']);
     return $zmail;
 }