Пример #1
0
 /**
  *  Check cron table if need and send some letters
  */
 public function check()
 {
     if (!Config::get('main.cron') or !Config::get('main.selfCron')) {
         return false;
     }
     $ids = array();
     $result = DB::select()->from(Config::get('main.tableCron'))->limit(Config::get('main.selfCron'))->as_object()->execute();
     foreach ($result as $obj) {
         $ids[] = $obj->id;
         Email::send($obj->subject, $obj->text, $obj->email);
     }
     if (count($ids)) {
         DB::delete(Config::get('main.tableCron'))->where('id', 'IN', $ids)->execute();
     }
 }
Пример #2
0
 function sendAction()
 {
     $emails = array();
     $list = array();
     if ($_POST) {
         $post = $_POST['FORM'];
         $subscribers = DB::select('email', 'hash', 'name')->from('subscribers')->where('status', '=', 1)->find_all();
         foreach ($subscribers as $obj) {
             if (filter_var($obj->email, FILTER_VALIDATE_EMAIL) and !in_array($obj->email, $emails)) {
                 $emails[] = $obj;
                 $list[] = $obj->email;
             }
         }
         if (!trim(Arr::get($post, 'subject'))) {
             Message::GetMessage(0, 'Поле "Тема" не может быть пустым!');
         } else {
             if (!trim(Arr::get($post, 'text'))) {
                 Message::GetMessage(0, 'Поле "Содержание" не может быть пустым!');
             } else {
                 if (empty($emails)) {
                     Message::GetMessage(0, 'Список выбраных E-Mail для рассылки пуст!');
                 } else {
                     $data = $post;
                     $data['count_emails'] = count($list);
                     $data['emails'] = implode(';', $list);
                     $res = Common::insert($this->tablename, $data)->execute();
                     foreach ($emails as $obj) {
                         $link = 'http://' . Arr::get($_SERVER, 'HTTP_HOST') . '/unsubscribe/hash/' . $obj->hash;
                         $from = array('{{unsubscribe}}', '{{user_name}}', '{{site}}', '{{date}}');
                         $to = array($link, $obj->name, Arr::get($_SERVER, 'HTTP_HOST'), date('d.m.Y'));
                         $message = str_replace($from, $to, Arr::get($post, 'text'));
                         $subject = str_replace($from, $to, Arr::get($post, 'subject'));
                         if (!Config::get('main.cron')) {
                             Email::send($subject, $message, $obj->email);
                         } else {
                             $data = array('subject' => $subject, 'text' => $message, 'email' => $obj->email);
                             $res = Common::insert(Config::get('main.tableCron'), $data)->execute();
                         }
                     }
                     Message::GetMessage(1, 'Письмо успешно разослано ' . $data['count_emails'] . ' подписчикам!');
                     HTTP::redirect('backend/' . Route::controller() . '/' . Route::action());
                 }
             }
         }
         $result = Arr::to_object($post);
     } else {
         $result = Arr::to_object(array('subscribers' => 1));
     }
     $this->_toolbar = Widgets::get('Toolbar/Subscribe');
     $this->_seo['h1'] = 'Отправка письма';
     $this->_seo['title'] = 'Отправка письма';
     $this->setBreadcrumbs('Отправка письма', 'backend/' . Route::controller() . '/add');
     $this->_content = View::tpl(array('obj' => $result, 'tpl_folder' => $this->tpl_folder, 'tablename' => $this->tablename), $this->tpl_folder . '/Send');
 }
Пример #3
0
 public static function sendOrderMessageUser(array $data)
 {
     $ip = \Core\System::getRealIP();
     $mail = DB::select()->from('mail_templates')->where('status', '=', 1)->where('id', '=', 12)->find();
     if (count($mail) == 0) {
         return false;
     }
     $dataTpl = \Core\View::tpl(array('order' => $data['order'], 'order_text' => $data['order_text']), 'Orders/Email');
     $from = array('{{site}}', '{{order_number}}', '{{link_user}}', '{{data}}', '{{ip}}', '{{date}}', '{{event_name}}');
     $to = array(Arr::get($_SERVER, 'HTTP_HOST'), $data['id_order'], '<a href="http://' . Arr::get($_SERVER, 'HTTP_HOST') . '/payment/' . $data['id_order'] . '">Ссылка</a>', $dataTpl, $ip, date('d.m.Y H:i'), $data['order']['event_name']);
     $subject = str_replace($from, $to, $mail->subject);
     $text = str_replace($from, $to, $mail->text);
     Email::send($subject, $text, $data['order']['email']);
 }
Пример #4
0
 function sendAction()
 {
     $id = (int) Route::param('id');
     $user = Model::getRow($id);
     if (!$user) {
         Message::GetMessage(0, 'Пользователь не существуют!');
         HTTP::redirect('backend/admins/index');
     }
     if ($user->deleted || $user->status == 0) {
         Message::GetMessage(1, 'Пользователь удален или заблокирован!');
         HTTP::redirect('backend/admins/index');
     }
     if (!filter_var($user->email, FILTER_VALIDATE_EMAIL)) {
         Message::GetMessage(1, 'E-Mail пользователя некорректен!');
         HTTP::redirect('backend/admins/index');
     }
     // Generate new password for user and save it to his account
     $password = User::factory()->generate_random_password();
     User::factory()->update_password($user->id, $password);
     // Send E-Mail to user with instructions how recover password
     $mail = Common::factory('mail_templates')->getRow(5);
     if ($mail) {
         $from = array('{{site}}', '{{ip}}', '{{date}}', '{{password}}');
         $to = array(Arr::get($_SERVER, 'HTTP_HOST'), System::getRealIP(), date('d.m.Y H:i'), $password);
         $subject = str_replace($from, $to, $mail->subject);
         $text = str_replace($from, $to, $mail->text);
         Email::send($subject, $text, $user->email);
     }
     Message::GetMessage(1, 'Новый пароль отправлен на E-Mail пользователя!');
     HTTP::redirect('backend/admins/index');
 }
Пример #5
0
 public function broneAction()
 {
     // Check incoming data
     $event_name = Text::xssClean(Arr::get($this->post, 'event_name'));
     if (!$event_name) {
         $this->error('Вы не указали название события!');
     }
     $name = Text::xssClean(Arr::get($this->post, 'name'));
     if (!$name) {
         $this->error('Вы не указали имя!');
     }
     if (!filter_var(Arr::get($this->post, 'email'), FILTER_VALIDATE_EMAIL)) {
         $this->error('Вы указали неверный E-Mail!');
     }
     $phone = trim(Arr::get($this->post, 'phone'));
     if (!$phone or !preg_match('/^\\(\\d{3}\\) \\d{3}\\-\\d{2}\\-\\d{2}$/', $phone, $matches)) {
         $this->error('Номер телефона введен неверно!');
     }
     $text = Text::xssClean(Arr::get($this->post, 'text'));
     if (!$text) {
         $this->error('Вы не написали текст сообщения!');
     }
     // Create data for saving
     $data = array();
     $data['text'] = nl2br($text);
     $data['ip'] = System::getRealIP();
     $data['event_name'] = $event_name;
     $data['name'] = $name;
     $data['phone'] = Arr::get($this->post, 'phone');
     $data['email'] = Arr::get($this->post, 'email');
     $data['created_at'] = time();
     // Chec for bot
     $check = DB::select(array(DB::expr('COUNT(brone.id)'), 'count'))->from('brone')->where('ip', '=', Arr::get($data, 'ip'))->where('created_at', '>', time() - 60)->as_object()->execute()->current();
     if (is_object($check) and $check->count) {
         $this->error('Нельзя так часто отправлять сообщения! Пожалуйста, повторите попытку через минуту');
     }
     // Save contact message to database
     $keys = array();
     $values = array();
     foreach ($data as $key => $value) {
         $keys[] = $key;
         $values[] = $value;
     }
     $lastID = DB::insert('brone', $keys)->values($values)->execute();
     $lastID = Arr::get($lastID, 0);
     // Save log
     $qName = 'Сообщение из формы бронирования билетов';
     $url = '/backend/brone/edit/' . $lastID;
     Log::add($qName, $url, 2);
     // Send E-Mail to admin
     $mail = DB::select()->from('mail_templates')->where('id', '=', 13)->where('status', '=', 1)->as_object()->execute()->current();
     if ($mail) {
         $from = array('{{site}}', '{{event_name}}', '{{name}}', '{{email}}', '{{phone}}', '{{text}}', '{{ip}}', '{{date}}');
         $to = array(Arr::get($_SERVER, 'HTTP_HOST'), Arr::get($data, 'event_name'), Arr::get($data, 'name'), Arr::get($data, 'email'), Arr::get($data, 'phone'), Arr::get($data, 'text'), Arr::get($data, 'ip'), date('d.m.Y H:i'));
         $subject = str_replace($from, $to, $mail->subject);
         $text = str_replace($from, $to, $mail->text);
         Email::send($subject, $text);
     }
     $this->success('Сообщение отправлено!');
 }
Пример #6
0
 public function reportError($error, $log = true)
 {
     if ($log) {
         error_log($error);
     }
     if (defined('MAIL_ERRORS') && MAIL_ERRORS) {
         Email::sendRaw(SITE_EMAIL, '[' . SITE_NAME . '] Error', "{$error}\n\n" . Dump::light($this->request, true));
     }
 }
Пример #7
0
function email($to_name, $to_email, $subject, $body)
{
    $config = config()->email;
    $email = new Email($config->name, $config->email);
    return $email->send($to_name, $to_email, $subject, $body);
}