function execute(JitFilter $data) { require_once 'lib/mail/maillib.php'; try { $mail = tiki_get_admin_mail(); if ($replyto = $data->replyto->email()) { $mail->setReplyTo($replyto); } foreach ($data->to->email() as $to) { $mail->addTo($this->stripNp($to)); } foreach ($data->cc->email() as $cc) { $mail->addCc($this->stripNp($cc)); } foreach ($data->bcc->email() as $bcc) { $mail->addBcc($this->stripNp($bcc)); } $content = $this->parse($data->content->none()); $subject = $this->parse($data->subject->text()); $mail->setSubject(strip_tags($subject)); $bodyPart = new \Zend\Mime\Message(); $bodyMessage = new \Zend\Mime\Part($content); $bodyMessage->type = \Zend\Mime\Mime::TYPE_HTML; $bodyPart->setParts(array($bodyMessage)); $mail->setBody($bodyPart); tiki_send_email($mail); return true; } catch (Exception $e) { return false; } }
protected function execute(InputInterface $input, OutputInterface $output) { require_once 'lib/mail/maillib.php'; global $prefs; $logslib = TikiLib::lib('logs'); tiki_mail_setup(); $output->writeln('Mail queue processor starting...'); $messages = \TikiDb::get()->fetchAll('SELECT messageId, message FROM tiki_mail_queue'); foreach ($messages as $message) { $output->writeln('Sending message ' . $message['messageId'] . '...'); $mail = unserialize($message['message']); if ($mail) { try { tiki_send_email($mail); $title = 'mail'; } catch (Zend\Mail\Exception\ExceptionInterface $e) { $title = 'mail error'; } if ($title == 'mail error' || $prefs['log_mail'] == 'y') { foreach ($mail->getTo() as $destination) { $logslib->add_log($title, $destination->getEmail() . '/' . $mail->getSubject()); } foreach ($mail->getCc() as $destination) { $logslib->add_log($title, $destination->getEmail() . '/' . $mail->getSubject()); } foreach ($mail->getBcc() as $destination) { $logslib->add_log($title, $destination->getEmail() . '/' . $mail->getSubject()); } } if ($title == 'mail error') { $query = 'UPDATE tiki_mail_queue SET attempts = attempts + 1 WHERE messageId = ?'; $output->writeln('Failed.'); } else { $query = 'DELETE FROM tiki_mail_queue WHERE messageId = ?'; $output->writeln('Sent.'); } \TikiDb::get()->query($query, array($message['messageId'])); } else { $output->writeln('ERROR: Unable to unserialize the mailer object.'); } } $output->writeln('Mail queue processed...'); }
/** * @param $email * @param $recipientName * @param $subject * @param $textBody */ function tiki_send_admin_mail($email, $recipientName, $subject, $textBody) { $mail = tiki_get_admin_mail(); $mail->addTo($email, $recipientName); $mail->setSubject($subject); $mail->setBody($textBody); tiki_send_email($mail); }
function send($recipients, $type = 'mail') { global $tikilib, $prefs; $logslib = TikiLib::lib('logs'); $this->mail->getHeaders()->removeHeader('to'); foreach ((array) $recipients as $to) { $this->mail->addTo($to); } if ($prefs['zend_mail_handler'] == 'smtp' && $prefs['zend_mail_queue'] == 'y') { $query = "INSERT INTO `tiki_mail_queue` (message) VALUES (?)"; $bindvars = array(serialize($this->mail)); $tikilib->query($query, $bindvars, -1, 0); $title = 'mail'; } else { try { tiki_send_email($this->mail); $title = 'mail'; } catch (Zend\Mail\Exception\ExceptionInterface $e) { $title = 'mail error'; } if ($title == 'mail error' || $prefs['log_mail'] == 'y') { foreach ($recipients as $u) { $logslib->add_log($title, $u . '/' . $this->mail->getSubject()); } } } return $title == 'mail'; }
public function send($nl_info, $info, $browser = true, &$sent, &$errors, &$logFileName) { global $prefs, $section; $headerlib = TikiLib::lib('header'); $tikilib = TikiLib::lib('tiki'); $userlib = TikiLib::lib('user'); $smarty = TikiLib::lib('smarty'); $users = $this->get_all_subscribers($nl_info['nlId'], $nl_info['unsubMsg'] == 'y'); if (empty($info['editionId'])) { $info['editionId'] = $this->replace_edition($nl_info['nlId'], $info['subject'], $info['data'], 0, 0, true, $info['datatxt'], $info['files'], $info['wysiwyg']); } else { $this->replace_edition($nl_info['nlId'], $info['subject'], $info['data'], 0, $info['editionId'], true, $info['datatxt'], $info['files'], $info['wysiwyg']); } if (isset($info['begin'])) { $this->memo_subscribers_edition($info['editionId'], $users); } $remaining = $this->table('tiki_sent_newsletters_errors')->fetchColumn('email', array('editionId' => $info['editionId'])); $sent = array(); $errors = array(); $toSend = array(); foreach ($users as $uInfo) { $userEmail = $uInfo['login']; $email = trim($uInfo['email']); if ($userEmail == '') { $userEmail = $userlib->get_user_by_email($email); } $language = !$userEmail ? $prefs['site_language'] : $tikilib->get_user_preference($userEmail, "language", $prefs['site_language']); if (preg_match('/([a-zA-Z0-9])+([a-zA-Z0-9\\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\\._-]+)+/', $email)) { if (in_array($email, $remaining)) { $uInfo['user'] = $userEmail; $uInfo['email'] = $email; $uInfo['language'] = $language; $toSend[$email] = $uInfo; } else { $sent[] = $email; } } else { $errors[] = array("user" => $userEmail, "email" => $email, "msg" => tra("invalid email")); } } $users = array_values($toSend); $logFileName = $prefs['tmpDir'] . '/public/newsletter-log-' . $info['editionId'] . '.txt'; if (($logFileHandle = fopen($logFileName, 'a')) == false) { $logFileName = ''; } $smarty->assign('sectionClass', empty($section) ? '' : "tiki_{$section} "); if ($browser) { echo $smarty->fetch('send_newsletter_header.tpl'); } if ($browser) { @ini_set('zlib.output_compression', 0); } $throttleLimit = (int) $prefs['newsletter_batch_size']; foreach ($users as $us) { $tikilib->clear_cache_user_preferences(); $email = $us['email']; if ($browser) { if (@ob_get_level() == 0) { @ob_start(); } $emailsent = count($sent) + 1; // Browsers needs a certain amount of data, for each flush, to display something print str_repeat(' ', 4096) . "\n"; print '<div class="confirmation">' . " Total emails sent: " . $emailsent . tra(" after sending to") . " '<b>{$email}</b>': <font color="; } try { $zmail = $this->get_edition_mail($info['editionId'], $us, $info['is_html']); if (!$zmail) { continue; } tiki_send_email($zmail); $sent[] = $email; if ($browser) { print "'green'>" . tra('OK'); } $this->delete_edition_subscriber($info['editionId'], $us); $logStatus = 'OK'; } catch (Zend\Mail\Exception\ExceptionInterface $e) { if ($browser) { print "'red'>" . tra('Error') . " - {$e->getMessage()}"; } $errors[] = array("user" => $us['user'], "email" => $email, "msg" => $e->getMessage()); $this->mark_edition_subscriber($info['editionId'], $us); $logStatus = 'Error'; } if ($logFileHandle) { @fwrite($logFileHandle, "{$email} : {$logStatus}\n"); } if ($browser) { print "</font></div>\n"; // Flush output to force the browser to display email addresses as soon as emails are sent // This should avoid CGI and/or proxy and/or browser timeouts when sending to a lot of emails @ob_flush(); @flush(); @ob_end_flush(); } if ($prefs['newsletter_throttle'] === 'y' && 0 >= --$throttleLimit) { $rate = (int) $prefs['newsletter_pause_length']; print '<div class="throttle" data-edition="' . $info['editionId'] . '" data-rate="' . $rate . '">' . tr('Limiting the email send rate. Resuming in %0 seconds.', $rate) . '</div>'; exit; } } $info['editionId'] = $this->replace_edition($nl_info['nlId'], $info['subject'], $info['data'], count($sent), $info['editionId'], false, $info['datatxt'], $info['files'], $info['wysiwyg']); foreach ($info['files'] as $k => $f) { if ($f['savestate'] == 'tikitemp') { $newpath = $prefs['tmpDir'] . '/newsletterfile-' . $f['filename']; rename($f['path'], $newpath); unlink($f['path'] . '.infos'); $info['files'][$k]['savestate'] = 'tiki'; $info['files'][$k]['path'] = $newpath; } } if ($logFileHandle) { @fclose($logFileHandle); } }