static function queueEmail($to, $cc, $bcc, $from, $subject, $body = false, $type = 'text/html', $encoding = '8bit', $attachments = array()) { $cron = CronEvents::getByName('send_notifications_through_cron'); if ($cron instanceof CronEvent && $cron->getEnabled()) { $qm = new QueuedEmail(); // set To if (!is_array($to)) { $to = array($to); } $qm->setTo(implode(";", $to)); // set CC if ($cc != null) { if (!is_array($cc)) { $cc = array($cc); } $qm->setCc(implode(";", $cc)); } // set BCC if ($bcc != null) { if (!is_array($bcc)) { $bcc = array($bcc); } $qm->setBcc(implode(";", $bcc)); } // set from $qm->setFrom($from); // set subject $qm->setSubject($subject); // set body $qm->setBody($body); // set attachments if ($qm->columnExists('attachments')) { $qm->setColumnValue('attachments', json_encode($attachments)); } $qm->save(); } else { // not using cron try { $sent_ok = self::sendEmail($to, $from, $subject, $body, $type, $encoding, $attachments); if ($sent_ok) { // save notification history when notifications are not sent by cron self::saveNotificationHistory(array('to' => $to, 'cc' => $cc, 'bcc' => $bcc, 'from' => $from, 'subject' => $subject, 'body' => $body, 'attachments' => json_encode($attachments), 'timestamp' => DateTimeValueLib::now()->toMySQL())); } } catch (Exception $e) { // save log in server if (defined('EMAIL_ERRORS_LOGDIR') && file_exists(EMAIL_ERRORS_LOGDIR) && is_dir(EMAIL_ERRORS_LOGDIR)) { $err_msg = ROOT_URL . "\nError sending notification (subject={$subject}) using account {$from}\n\nError detail:\n" . $e->getMessage() . "\n" . $e->getTraceAsString(); file_put_contents(EMAIL_ERRORS_LOGDIR . basename(ROOT), $err_msg, FILE_APPEND); } } } }
static function queueEmail($to, $from, $subject, $body = false, $type = 'text/html', $encoding = '8bit', $attachments = array()) { $cron = CronEvents::getByName('send_notifications_through_cron'); if ($cron instanceof CronEvent && $cron->getEnabled()) { $qm = new QueuedEmail(); if (!is_array($to)) { $to = array($to); } $qm->setTo(implode(";", $to)); $qm->setFrom($from); $qm->setSubject($subject); $qm->setBody($body); if ($qm->columnExists('attachments')) $qm->setColumnValue('attachments', json_encode($attachments)); $qm->save(); } else { self::sendEmail($to, $from, $subject, $body, $type, $encoding, $attachments); } }