From b2835e0954b01d0fdb2c0031b23f0b13bfbe6b19 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Wed, 15 Dec 2021 21:32:51 +0300 Subject: [PATCH] =?UTF-8?q?[*]=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D1=8C=D0=BC=D0=B0=20=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D1=82=D0=BE=D1=80=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/func.php | 34 ++++++++++------- inc/lib/CMail.class.php | 85 ----------------------------------------- mailings.php | 15 +------- 3 files changed, 22 insertions(+), 112 deletions(-) diff --git a/inc/func.php b/inc/func.php index 0e8a07d..4d627ee 100644 --- a/inc/func.php +++ b/inc/func.php @@ -262,29 +262,37 @@ function getOS() { /** * Отправка уведомления на почту администратору */ - function adminSendMail($subject, $message, $file = false){ +function adminSendMail($subject, $message, $file = false) +{ $mail = new CMail; - $mail->from('iot@'.$_SERVER['SERVER_NAME'], 'Система оповещений IoT Core'); + $mail->dump = true; + $mail->dumpPath = $_SERVER['DOCUMENT_ROOT'] . '/uploads/emails'; + $mail->from('iot@' . $_SERVER['SERVER_NAME'], 'IoT Core Board v.' . VERSION); $mail->to(ADMIN_EMAIL, 'Администратор панели'); $mail->subject = $subject; - $mail->body = ' -

Уведомление от системы IoT Core

-

'.$message.'

-
-

- С уважением, система IoT Core Board v.'.VERSION.' -
http://'.$_SERVER['SERVER_NAME'].' -

- '; + $mail->assignTemplateVars( + array( + 'HEADER' => 'Автоматическая рассылка', + 'MESSAGE' => $message, + 'TITLE' => 'Уведомление от панели', + 'LINK' => 'https://new-dev.it-stories.ru/', + 'LINKNAME' => 'Перейти в панель', + 'HOME' => 'https://it-stories.ru' + ) + ); + + $mail->template = 'default_red'; + $mail->templateDir = $_SERVER['DOCUMENT_ROOT'] . '/assets/mail_templates'; // прикрепляем лог, если он есть - if(isset($file) and !empty($file) and file_exists($file)){ + if (isset($file) and !empty($file) and file_exists($file)) { $mail->addFile($file); } + $mail->send(); return; - } +} /** diff --git a/inc/lib/CMail.class.php b/inc/lib/CMail.class.php index a79c095..72ccd05 100644 --- a/inc/lib/CMail.class.php +++ b/inc/lib/CMail.class.php @@ -218,89 +218,4 @@ class CMail { return $res; } - - /** - * Отправка с использованием встроенных стилей - */ - public function sendDefault() - { - if (empty($this->toEmail)) { - return false; - } - - // От кого - $from = (empty($this->fromName)) ? $this->fromEmail : '=?UTF-8?B?' . base64_encode($this->fromName) . '?= <' . $this->fromEmail . '>'; - - // Кому - $array_to = array(); - foreach (explode(',', $this->toEmail) as $row) { - $row = trim($row); - if (!empty($row)) { - $array_to[] = (empty($this->toName)) ? $row : '=?UTF-8?B?' . base64_encode($this->toName) . '?= <' . $row . '>'; - } - } - - // Тема письма - $subject = (empty($this->subject)) ? 'No subject' : $this->subject; - - // Текст письма - $body = ' - - - - - - ' . $this->body . ' - - '; - - // Добавление стилей к тегам - $body = $this->addHtmlStyle($body); - - $boundary = md5(uniqid(time())); - - // Заголовок письма - $headers = array( - 'Content-Type: multipart/mixed; boundary="' . $boundary . '"', - 'Content-Transfer-Encoding: 7bit', - 'MIME-Version: 1.0', - 'From: ' . $from, - 'Date: ' . date('r') - ); - - // Тело письма - $message = array( - '--' . $boundary, - 'Content-Type: text/html; charset=UTF-8', - 'Content-Transfer-Encoding: base64', - '', - chunk_split(base64_encode($body)) - ); - - if (!empty($this->_files)) { - foreach ($this->_files as $row) { - $message = array_merge($message, array('', '--' . $boundary), $row); - } - } - - $message[] = ''; - $message[] = '--' . $boundary . '--'; - $res = array(); - - foreach ($array_to as $to) { - // Дамп письма в файл - if ($this->dump == true) { - if (empty($this->dumpPath)) { - $this->dumpPath = dirname(__FILE__) . '/uploads'; - } - - $dump = array_merge($headers, array('To: ' . $to, 'Subject: ' . $subject, ''), $message); - $file = $this->safeFile($this->dumpPath . '/' . date('Y-m-d_H-i-s') . '.eml'); - file_put_contents($file, implode("\r\n", $dump)); - } - $res[] = mb_send_mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers)); - } - - return $res; - } } \ No newline at end of file diff --git a/mailings.php b/mailings.php index a2b421b..e2c9b73 100644 --- a/mailings.php +++ b/mailings.php @@ -6,20 +6,7 @@ require_once __DIR__ . '/inc/bootstrap.php'; require_once __DIR__ . '/inc/header.php'; if(isset($_REQUEST['save']) and $_REQUEST['save'] == 'Y'): - //TODO: делаем рассылку - /* - Array ( - [save] => Y - [template] => default - [subject] => Почтовая рассылка IoT Core Board - [header] => Заголовок - [message] => ТЕкст123 - 1234567 - [admin] => on - [user] => on - ) - */ $userEmails = []; if(isset($_REQUEST['admin']) and $_REQUEST['admin'] == 'on') { @@ -62,7 +49,7 @@ if(isset($_REQUEST['save']) and $_REQUEST['save'] == 'Y'): 'TITLE' => $_REQUEST['title'], 'LINK' => 'https://it-stories.ru/', 'LINKNAME' => 'Перейти в панель', - 'SERVERNAME' => 'it-stories.ru' + 'HOME' => 'https://it-stories.ru' ) );