WHERE EN.sended = 0 ORDER BY EN.created LIMIT 100 FOR UPDATE'); // <- lock пока не разошлём письма (100) if (!empty($aNotify)) { $mail = new CMail(); $tpl = $oBff->Sendmail_getMailTemplate('bbs_comments_notify'); foreach ($aNotify as $v) { try { $mail->From = BFF_EMAIL_NOREPLY; $mail->FromName = BFF_EMAIL_FROM_NAME; $mail->Subject = $tpl['subject']; $mail->AltBody = ''; $mail->MsgHTML(nl2br(strtr($tpl['body'], array('{item_id}' => $v['item_id'], '{item_url}' => SITEURL . '/item/' . $v['item_id'], '{item_comment_url}' => SITEURL . '/item/' . $v['item_id'] . '?comments=1', '{comment}' => $v['comment'])))); $mail->AddAddress($v['email']); $res = $mail->Send() ? 1 : 0; if ($res) { $aNotifyID[] = $v['id']; } $mail->ClearAddresses(); } catch (Exception $e) { $log->log('enotify error: ' . $e->getMessage()); $mail->SmtpClose(); } usleep(300000); // sleep for 0.3 second } if (!empty($aNotifyID)) { $oDb->execute('UPDATE ' . TABLE_BBS_ITEMS_COMMENTS_ENOTIFY . ' SET sended = 1 WHERE id IN (' . join(',', $aNotifyID) . ')'); $oDb->execute('DELETE FROM ' . TABLE_BBS_ITEMS_COMMENTS_ENOTIFY . ' WHERE id IN (' . join(',', $aNotifyID) . ')');
function ajax() { if (!$this->haveAccessTo('massend-clients')) { $this->ajaxResponse(Errors::ACCESSDENIED); } if (bff::$isAjax) { switch (func::POSTGET('action')) { case 'massend-filter': $bClients = func::POSTGET('clients') ? 1 : 0; $bEmployees = func::POSTGET('employees') ? 1 : 0; $bUsers = func::POSTGET('users') ? 1 : 0; $bUsers = func::POSTGET('usersall') && $bUsers ? 2 : $bUsers; $bExludeBlocked = func::POSTGET('blocked') ? 1 : 0; $this->ajaxResponse($this->getReceiversOptions($bClients, $bEmployees, $bUsers, $bExludeBlocked)); break; case 'massend': $bClients = func::POSTGET('clients') ? 1 : 0; $bEmployees = func::POSTGET('employees') ? 1 : 0; $bUsers = func::POSTGET('users') ? 1 : 0; $aReceivers = $this->getReceiversInfo($bClients || $bEmployees, $bUsers, func::POST('receivers', false)); $sFrom = func::POST('from', true); $sSubject = func::POST('subject', true); $sBodyHTML = func::POST('body', true); if (false && count($aReceivers) > 0 && !empty($sFrom) && !empty($sSubject) && !empty($sBodyHTML)) { $mailer = new CMail(); $mailer->From = $sFrom; $mailer->Subject = $sSubject; $mailer->MsgHTML($sBodyHTML); //определяем какой текст требует обработки шаблонизатором $aTemplateVars = array('{name}', '{login}', '{email}', '{password}'); str_replace($aTemplateVars, '', $sFrom, $bPrepareFrom); str_replace($aTemplateVars, '', $sSubject, $bPrepareSubject); str_replace($aTemplateVars, '', $sBodyHTML, $bPrepareBodyHTML); foreach ($aReceivers as $receiver) { set_time_limit(30); // sets (or resets) maximum execution time to 30 seconds) $mailer->AddAddress($receiver['email'], $receiver['name']); $aTemplateData = array('{name}' => $receiver['name'], '{login}' => $receiver['login'], '{email}' => $receiver['email'], '{password}' => $receiver['password']); //prepare FROM if ($bPrepareFrom) { $mailer->From = strtr($sFrom, $aTemplateData); } //prepare SUBJECT if ($bPrepareSubject) { $mailer->Subject = strtr($sSubject, $aTemplateData); } //prepare BODY-HTML if ($bPrepareBodyHTML) { $mailer->MsgHTML(strtr($sBodyHTML, $aTemplateData)); } $mailer->Send(); $mailer->ClearAddresses(); usleep(1000000); // sleep for 1 second } } $this->ajaxResponse($aReceivers); break; } } $this->ajaxResponse(Errors::IMPOSSIBLE); }
function subscribe_finish() { set_time_limit(0); $aSendedID = array(); $aReceivers = $this->db->select('SELECT I.user_id, U.user_id as id, U.login, U.password FROM ' . TABLE_ITEMS . ' I, ' . TABLE_USERS . ' U WHERE I.status = ' . ITEMS_STATUS_COMPLETED . ' AND I.user_id!=1 AND I.user_id = U.user_id AND I.id NOT IN( 39, 41, 70 ) GROUP BY I.user_id ORDER BY U.login ASC'); //echo '<pre>', print_r($aReceivers, true), '</pre>'; exit; // $aReceivers = array( // array('id'=>1, 'login'=>'*****@*****.**', 'password'=>'x123') // ); # инициализируем класс рассылки $mailer = new CMail(); $mailer->From = config::get('mail_noreply', BFF_EMAIL_NOREPLY); //"E-Mail адрес уведомлений" из настроек сайта # подготавливаем заголовок письма $mailer->FromName = 'ILove.zp.ua'; $mailer->Subject = 'ILove.zp.ua - итоги акции!'; $sTpl = nl2br($this->getMailTemplateContent('member_subscribe_open')); foreach ($aReceivers as $v) { if (func::IsEmailAddress($v['login'])) { # подготавливаем тело письма $mailer->AltBody = ''; $mailer->MsgHTML(strtr($sTpl, array('{login}' => $v['login'], '{password}' => $v['password']))); # отправляем письмо $mailer->AddAddress($v['login']); if ($mailer->Send()) { $aSendedID[] = $v['id']; } $mailer->ClearAddresses(); usleep(150000); // sleep for 0.15 second } } echo sizeof($aReceivers), ' / ', sizeof($aSendedID), '<br/>'; echo '<pre>', print_r($aSendedID, true), '</pre>'; exit; }
function sendMail($to, $subject, $body, $from = '', $formName = '') { $mailer = new CMail(); set_time_limit(30); if (!empty($from)) { $mailer->From = $from; } if (!empty($formName)) { $mailer->FromName = $formName; } $mailer->Subject = $subject; $mailer->MsgHTML($body); $mailer->AddAddress($to, ''); $result = $mailer->Send(); usleep(1000000); // sleep for 1 second return $result; }