Example #1
0
 /**
  * Sent Birthday emails.
  *
  * @return integer Total emails sent.
  */
 public function sendMails()
 {
     $oBirths = (new BirthdayCoreModel())->get();
     $oMail = new Mail();
     foreach ($oBirths as $oBirth) {
         // Do not send any emails at the same time to avoid overloading the mail server.
         if (self::$_iTotalSent > 300) {
             sleep(10);
         }
         $this->view->content = t('Hello %0%!', $oBirth->firstName) . '<br />' . t("All %site_name%'s team wish you a very happy birthday!") . '<br />' . t('Enjoy it well and enjoy yourself!');
         $sMsgHtml = $this->view->parseMail(PH7_PATH_SYS . 'global/' . PH7_VIEWS . PH7_DEFAULT_THEME . '/mail/sys/mod/user/birthday.tpl', $oBirth->email);
         $aInfo = ['subject' => t('Happy Birthday %0%!', $oBirth->firstName), 'to' => $oBirth->email];
         $oMail->send($aInfo, $sMsgHtml);
         self::$_iTotalSent++;
     }
     unset($oMail, $oBirths);
     return self::$_iTotalSent;
 }
 /**
  * Send the newsletter to subscribers.
  *
  * @return array (integer | integer) ['status', 'nb_mail_sent']
  */
 public function sendMessages()
 {
     $bOnlySubscribers = $this->httpRequest->postExists('only_subscribers');
     $iRes = 0;
     // Default value
     $sSubscribersMethod = $bOnlySubscribers ? 'getSubscribers' : 'getProfiles';
     $oSubscribers = $this->_oSubscriptionModel->{$sSubscribersMethod}();
     $oMail = new Mail();
     foreach ($oSubscribers as $oSubscriber) {
         $this->view->content = $this->httpRequest->post('body', Http::NO_CLEAN);
         $sMsgHtml = $this->view->parseMail(PH7_PATH_SYS . 'global/' . PH7_VIEWS . PH7_TPL_NAME . '/mail/sys/mod/newsletter/msg.tpl', $oSubscriber->email);
         $aInfo = ['subject' => $this->httpRequest->post('subject'), 'to' => $oSubscriber->email, 'to_name' => $oSubscriber->firstName];
         if (!($iRes = $oMail->send($aInfo, $sMsgHtml))) {
             break;
         }
         // Do not send all emails at the same time to avoid overloading the mail server.
         if (++self::$_iTotalSent > 250) {
             sleep(10);
         }
     }
     unset($oMail, $oSubscribers);
     return ['status' => $iRes, 'nb_mail_sent' => self::$_iTotalSent];
 }