Exemplo n.º 1
0
 public function execute()
 {
     set_time_limit(0);
     $notifiedEmails = array();
     $emailScheduling = SJB_Settings::getSettingByName('email_scheduling');
     $numberEmails = SJB_Settings::getSettingByName('number_emails');
     $emailsSend = SJB_Settings::getSettingByName('send_emails');
     $limit = $numberEmails - $emailsSend;
     $limit = $limit > 0 ? $limit : 20;
     $letters = SJB_DB::query('SELECT * FROM `email_scheduling` ORDER BY `id` ASC LIMIT 0, ?n', $limit);
     if ($emailScheduling && $numberEmails || count($letters)) {
         foreach ($letters as $letter) {
             $params = $letter;
             unset($params['id']);
             $email = new SJB_Email($params['email']);
             $email->setSubject($params['subject']);
             $email->setText($params['text']);
             $email->setFile($params['file']);
             if ($email->send(true)) {
                 SJB_DB::query('DELETE FROM `email_scheduling` WHERE `id` = ?n', $letter['id']);
                 array_push($notifiedEmails, $params['email']);
             }
         }
     }
     $tp = SJB_System::getTemplateProcessor();
     $tp->assign('notified_emails', $notifiedEmails);
     $schedulerLog = $tp->fetch('email_scheduler_log.tpl');
     SJB_HelperFunctions::writeCronLogFile('email_scheduler.log', $schedulerLog);
 }
Exemplo n.º 2
0
 /**
  * @param $emailSID
  * @throws Exception
  */
 protected function resendEmailBySID($emailSID)
 {
     $emailToSend = SJB_EmailLogManager::getObjectBySID($emailSID);
     if (!$emailToSend instanceof SJB_EmailLog) {
         throw new Exception('Not valid email log ID to resend');
     }
     $email = new SJB_Email($emailToSend->getPropertyValue('email'));
     $email->setSubject($emailToSend->getPropertyValue('subject'));
     $email->setText($emailToSend->getPropertyValue('message'));
     if (!$email->send()) {
         throw new Exception('Email log > Resend Function: The message were not resent. Please check the settings');
     }
 }