[+] добавлен функционал почтовых рассылок
This commit is contained in:
1 parent
a2eae57a11
commit
689753ddf1
7 files changed
+232
-382
No files matched your search
Vendored
+5
-3
@@ -81,7 +81,10 @@
|
||||
.container .masthead {
|
||||
padding: 18px 0;
|
||||
background: #71bc37;
|
||||
color: white; }
|
||||
color: white;
|
||||
margin-top: 40px;
|
||||
display: block;
|
||||
}
|
||||
.container .masthead h1 {
|
||||
margin: 0 auto !important;
|
||||
max-width: 90%; }
|
||||
@@ -124,7 +127,6 @@
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>{FOOTER}</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -135,7 +137,7 @@
|
||||
<table>
|
||||
<tr>
|
||||
<td class="content footer" align="center">
|
||||
<p>Сообщение сгенерировано системой <a href="{HOME}">IoT Core Board</a>, {SERVERNAME}</p>
|
||||
<p>Сообщение сгенерировано системой <a href="{HOME}">IoT Core Board</a></p>
|
||||
<p><a href="mailto:rsgrinko@gmail.com">E-Mail: rsgrinko@gmail.com</a> | <a href="https://telegram.me/rsgrinko">Telegram @rsgrinko</a></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
+1
-31
@@ -274,36 +274,6 @@ function getOS() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Отправка уведомления на почту администратору с использованием шаблонов
|
||||
*/
|
||||
function adminSendMailWithTemplate($template, $subject, $message, $file = false){
|
||||
$mail = new CMail;
|
||||
$mail->from('iot@'.$_SERVER['SERVER_NAME'], 'Система оповещений IoT Core');
|
||||
$mail->to(ADMIN_EMAIL, 'Администратор панели');
|
||||
$mail->subject = $subject;
|
||||
$mail->assignTemplateVars(
|
||||
array(
|
||||
'HEADER' => 'IoT Core',
|
||||
'MESSAGE' => 'test0',
|
||||
'TITLE' => 'test title',
|
||||
'LINK' => 'https://it-stories.ru/',
|
||||
'LINKNAME' => 'Go to site',
|
||||
'FOOTER' => 'Thanks!',
|
||||
'SERVERNAME' => 'it-stories.ru'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
|
||||
// прикрепляем лог, если он есть
|
||||
if(isset($file) and !empty($file) and file_exists($file)){
|
||||
$mail->addFile($file);
|
||||
}
|
||||
$mail->sendUsingTemplate($template);
|
||||
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Отправка уведомления пользователю
|
||||
*
|
||||
@@ -332,7 +302,7 @@ function adminSendMailWithTemplate($template, $subject, $message, $file = false)
|
||||
if(isset($file) and !empty($file) and file_exists($file)){
|
||||
$mail->addFile($file);
|
||||
}
|
||||
$mail->send();
|
||||
$mail->sendDefault();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ if(!CUser::is_user() and $_SERVER['REQUEST_URI'] !== '/login.php') {
|
||||
</li>
|
||||
|
||||
<li class="nav-item <?php echo (basename($_SERVER['PHP_SELF']) == 'mailings.php') ? 'active' : '';?>">
|
||||
<a href="<?php echo HOME; ?>/mailings.php"><i class="fa fa-tasks"></i> Почтовые рассылки</a>
|
||||
<a href="<?php echo HOME; ?>/mailings.php"><i class="fa fa-envelope-o"></i> Почтовые рассылки</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item <?php echo (basename($_SERVER['PHP_SELF']) == 'cron.php' or basename($_SERVER['PHP_SELF']) == 'add_cron.php' or basename($_SERVER['PHP_SELF']) == 'edit_cron.php') ? 'active' : '';?>">
|
||||
|
||||
+87
-340
@@ -1,346 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Класс для отправки E-mail
|
||||
* Данный файл входит в состав системы IoT Core System
|
||||
* Разработчик: Роман Сергеевич Гринько
|
||||
* E-mail: rsgrinko@gmail.com
|
||||
* Cайт: https://it-stories.ru
|
||||
* @author rsgrinko@gmail.com
|
||||
*/
|
||||
|
||||
class CMail
|
||||
{
|
||||
/**
|
||||
* От кого
|
||||
*/
|
||||
public $fromEmail = '';
|
||||
public $fromName = '';
|
||||
|
||||
/**
|
||||
* Кому
|
||||
*/
|
||||
public $toEmail = '';
|
||||
public $toName = '';
|
||||
|
||||
/**
|
||||
* Тема
|
||||
*/
|
||||
public $subject = '';
|
||||
|
||||
/**
|
||||
* Текст
|
||||
*/
|
||||
public $body = '';
|
||||
|
||||
/**
|
||||
* Массив с данными для подстановки в шаблон
|
||||
*/
|
||||
public $arrTemplate = [];
|
||||
|
||||
/**
|
||||
* Массив заголовков файлов
|
||||
*/
|
||||
private $_files = array();
|
||||
|
||||
/**
|
||||
* Управление дампированием
|
||||
*/
|
||||
public $dump = false;
|
||||
|
||||
/**
|
||||
* Директория куда сохранять письма
|
||||
*/
|
||||
public $dumpPath = '';
|
||||
|
||||
/**
|
||||
* CSS стили для тегов письма
|
||||
*/
|
||||
private $_styles = array(
|
||||
'body' => 'margin: 0 0 0 0; padding: 10px 10px 10px 10px; background: #ffffff; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
|
||||
'a' => 'color: #003399; text-decoration: underline; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
|
||||
'p' => 'margin: 0 0 20px 0; padding: 0 0 0 0; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
|
||||
'ul' => 'margin: 0 0 20px 20px; padding: 0 0 0 0; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
|
||||
'ol' => 'margin: 0 0 20px 20px; padding: 0 0 0 0; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
|
||||
'table' => 'margin: 0 0 20px 0; border: 1px solid #dddddd; border-collapse: collapse;',
|
||||
'th' => 'padding: 10px; border: 1px solid #dddddd; vertical-align: middle; background-color: #eeeeee; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
|
||||
'td' => 'padding: 10px; border: 1px solid #dddddd; vertical-align: middle; background-color: #ffffff; color: #000000; font-size: 14px; font-family: Arial, Helvetica, sans-serif; line-height: 18px;',
|
||||
'h1' => 'margin: 0 0 20px 0; padding: 0 0 0 0; color: #000000; font-size: 22px; font-family: Arial, Helvetica, sans-serif; line-height: 26px; font-weight: bold;',
|
||||
'h2' => 'margin: 0 0 20px 0; padding: 0 0 0 0; color: #000000; font-size: 20px; font-family: Arial, Helvetica, sans-serif; line-height: 24px; font-weight: bold;',
|
||||
'h3' => 'margin: 0 0 20px 0; padding: 0 0 0 0; color: #000000; font-size: 18px; font-family: Arial, Helvetica, sans-serif; line-height: 22px; font-weight: bold;',
|
||||
'h4' => 'margin: 0 0 20px 0; padding: 0 0 0 0; color: #000000; font-size: 16px; font-family: Arial, Helvetica, sans-serif; line-height: 20px; font-weight: bold;',
|
||||
'hr' => 'height: 1px; border: none; color: #dddddd; background: #dddddd; margin: 0 0 20px 0;'
|
||||
);
|
||||
|
||||
/**
|
||||
* Проверка существования файла
|
||||
* Если директория не существует - пытается её создать.
|
||||
* Если файл существует - к концу файла приписывает префикс.
|
||||
*/
|
||||
private function safeFile($filename)
|
||||
{
|
||||
$dir = dirname($filename);
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
|
||||
$info = pathinfo($filename);
|
||||
$name = $dir . '/' . $info['filename'];
|
||||
$ext = (empty($info['extension'])) ? '' : '.' . $info['extension'];
|
||||
$prefix = '';
|
||||
|
||||
if (is_file($name . $ext)) {
|
||||
$i = 1;
|
||||
$prefix = '_' . $i;
|
||||
|
||||
while (is_file($name . $prefix . $ext)) {
|
||||
$prefix = '_' . ++$i;
|
||||
}
|
||||
}
|
||||
|
||||
return $name . $prefix . $ext;
|
||||
}
|
||||
|
||||
/**
|
||||
* От кого
|
||||
*/
|
||||
public function from($email, $name = null)
|
||||
{
|
||||
$this->fromEmail = $email;
|
||||
$this->fromName = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Кому
|
||||
*/
|
||||
public function to($email, $name = null)
|
||||
{
|
||||
$this->toEmail = $email;
|
||||
$this->toName = $name;
|
||||
}
|
||||
|
||||
public function assignTemplateVars($arrVars) {
|
||||
$this->arrTemplate = $arrVars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавление файла к письму
|
||||
*/
|
||||
public function addFile($filename)
|
||||
{
|
||||
if (is_file($filename)) {
|
||||
$name = basename($filename);
|
||||
$fp = fopen($filename, 'rb');
|
||||
$file = fread($fp, filesize($filename));
|
||||
fclose($fp);
|
||||
$this->_files[] = array(
|
||||
'Content-Type: application/octet-stream; name="' . $name . '"',
|
||||
'Content-Transfer-Encoding: base64',
|
||||
'Content-Disposition: attachment; filename="' . $name . '"',
|
||||
'',
|
||||
chunk_split(base64_encode($file)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавление к тегам стили
|
||||
*/
|
||||
public function addHtmlStyle($html)
|
||||
{
|
||||
foreach ($this->_styles as $tag => $style) {
|
||||
preg_match_all('/<' . $tag . '([\s].*?)?>/i', $html, $matchs, PREG_SET_ORDER);
|
||||
foreach ($matchs as $match) {
|
||||
$attrs = array();
|
||||
if (!empty($match[1])) {
|
||||
preg_match_all('/[ ]?(.*?)=[\"|\'](.*?)[\"|\'][ ]?/', $match[1], $chanks);
|
||||
if (!empty($chanks[1]) && !empty($chanks[2])) {
|
||||
$attrs = array_combine($chanks[1], $chanks[2]);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($attrs['style'])) {
|
||||
$attrs['style'] = $style;
|
||||
} else {
|
||||
$attrs['style'] = rtrim($attrs['style'], '; ') . '; ' . $style;
|
||||
}
|
||||
|
||||
$compile = array();
|
||||
foreach ($attrs as $name => $value) {
|
||||
$compile[] = $name . '="' . $value . '"';
|
||||
}
|
||||
|
||||
$html = str_replace($match[0], '<' . $tag . ' ' . implode(' ', $compile) . '>', $html);
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Отправка
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
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 = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
' . $this->body . '
|
||||
</body>
|
||||
</html>';
|
||||
|
||||
// Добавление стилей к тегам
|
||||
$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;
|
||||
}
|
||||
|
||||
public function sendUsingTemplate($template = 'default') {
|
||||
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 = file_get_contents(__DIR__.'/../../assets/mail_templates/'.$template.'.html');
|
||||
foreach($this->arrTemplate as $templateKey => $templateValue){
|
||||
$body = str_replace('{'.$templateKey.'}', $templateValue, $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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Класс для отправки E-Mail с использованием почтовых шаблонов
|
||||
*/
|
||||
class CMail2 {
|
||||
class CMail {
|
||||
/**
|
||||
* Шаблон письма
|
||||
*/
|
||||
@@ -480,7 +142,7 @@ class CMail2 {
|
||||
}
|
||||
|
||||
/**
|
||||
* Отправка
|
||||
* Отправка с использованием шаблонов
|
||||
*/
|
||||
public function send() {
|
||||
if (empty($this->toEmail)) {
|
||||
@@ -556,4 +218,89 @@ class CMail2 {
|
||||
|
||||
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 = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
' . $this->body . '
|
||||
</body>
|
||||
</html>';
|
||||
|
||||
// Добавление стилей к тегам
|
||||
$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;
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,10 @@ if(CUser::is_user()) {
|
||||
/**
|
||||
* В случае неудачной попытки входа информируем администратора о данной ситуации
|
||||
*/
|
||||
$debugFile = $_SERVER['DOCUMENT_ROOT'].'/cache/auth_'.md5($_REQUEST['login'].$_REQUEST['pass']).'_time_'.time().'.txt';
|
||||
/*$debugFile = $_SERVER['DOCUMENT_ROOT'].'/cache/auth_'.md5($_REQUEST['login'].$_REQUEST['pass']).'_time_'.time().'.txt';
|
||||
file_put_contents($debugFile, print_r($_SERVER, true)."\n\n".print_r($_REQUEST, true)."".print_r(getClientInfo(), true));
|
||||
adminSendMail('Попытка вторжения', 'Неудачная попытка авториации в системе (IP: '.getIp().', '.$_REQUEST['login'].', '.$_REQUEST['pass'].', OS: '.getOS().')', $debugFile);
|
||||
unlink($debugFile);
|
||||
unlink($debugFile);*/
|
||||
|
||||
}
|
||||
} else {
|
||||
|
||||
+135
-4
@@ -7,6 +7,81 @@ 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') {
|
||||
$arUsers = $DB->query('SELECT id, email FROM users WHERE access_level="admin"');
|
||||
foreach($arUsers as $mailingUser) {
|
||||
$userEmails[] = $mailingUser['email'];
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_REQUEST['user']) and $_REQUEST['user'] == 'on') {
|
||||
$arUsers = $DB->query('SELECT id, email FROM users WHERE access_level="user"');
|
||||
foreach($arUsers as $mailingUser) {
|
||||
$userEmails[] = $mailingUser['email'];
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_REQUEST['demo']) and $_REQUEST['demo'] == 'on') {
|
||||
$arUsers = $DB->query('SELECT id, email FROM users WHERE access_level="demo"');
|
||||
foreach($arUsers as $mailingUser) {
|
||||
$userEmails[] = $mailingUser['email'];
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($_REQUEST['use_html_message']) and $_REQUEST['use_html_message'] == 'on') {
|
||||
$message = $_REQUEST['message'];
|
||||
} else {
|
||||
$message = nl2br($_REQUEST['message']);
|
||||
}
|
||||
|
||||
$mail = new CMail;
|
||||
$mail->dump = true;
|
||||
$mail->dumpPath = $_SERVER['DOCUMENT_ROOT'].'/uploads/emails';
|
||||
$mail->from('iot@'.$_SERVER['SERVER_NAME'], 'IoT Core Board v.'.VERSION);
|
||||
$mail->to(implode(',', $userEmails));
|
||||
$mail->subject = $_REQUEST['subject'];
|
||||
$mail->assignTemplateVars(
|
||||
array(
|
||||
'HEADER' => $_REQUEST['subject'],
|
||||
'MESSAGE' => $message,
|
||||
'TITLE' => $_REQUEST['title'],
|
||||
'LINK' => 'https://it-stories.ru/',
|
||||
'LINKNAME' => 'Перейти в панель',
|
||||
'SERVERNAME' => 'it-stories.ru'
|
||||
)
|
||||
);
|
||||
|
||||
$mail->template = 'default';
|
||||
$mail->templateDir = $_SERVER['DOCUMENT_ROOT'].'/assets/mail_templates';
|
||||
|
||||
/*
|
||||
// прикрепляем лог, если он есть
|
||||
if(isset($file) and !empty($file) and file_exists($file)){
|
||||
$mail->addFile($file);
|
||||
}*/
|
||||
$mail->send();
|
||||
?>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
alert("Почтовая рассылка отправлена");
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
endif;
|
||||
|
||||
|
||||
@@ -25,20 +100,76 @@ endif;
|
||||
<input type="hidden" name="save" value="Y">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-xs-12" for="template-select">Select</label>
|
||||
<label class="col-xs-12" for="template-select">Выберите шаблон письма:</label>
|
||||
<div class="col-sm-9">
|
||||
<select class="form-control" id="template-select" name="template" size="1">
|
||||
<?php foreach(CMail2::getMailTemplates() as $mailTemplate): ?>
|
||||
<?php foreach(CMail::getMailTemplates() as $mailTemplate): ?>
|
||||
<option value="<?php echo $mailTemplate; ?>"><?php echo $mailTemplate; ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-xs-12" for="subject-text-input">Тема письма:</label>
|
||||
<div class="col-sm-9">
|
||||
<input class="form-control" type="text" id="subject-text-input" name="subject" placeholder="Введите тему письма..." value="Почтовая рассылка IoT Core Board">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-xs-12" for="header-text-input">Заголовок письма:</label>
|
||||
<div class="col-sm-9">
|
||||
<input class="form-control" type="text" id="header-text-input" name="title" placeholder="Введите заголовок письма...">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
|
||||
|
||||
<label class="col-xs-12" for="body-textarea-input">Содержимое письма:</label>
|
||||
|
||||
<div class="col-xs-12">
|
||||
<p>
|
||||
<label class="css-input switch switch-sm switch-primary">
|
||||
<input type="checkbox" name="use_html_message"><span></span> HTML
|
||||
</label>
|
||||
</p>
|
||||
<textarea class="form-control" id="body-textarea-input" name="message" rows="6" placeholder="Введите содержимое письма..."></textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-xs-12" for="example-textarea-input">Выберите группы для рассылки:</label>
|
||||
<div class="col-xs-12">
|
||||
<p>
|
||||
<label class="css-input switch switch-sm switch-primary">
|
||||
<input type="checkbox" name="admin"><span></span> Администрация
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label class="css-input switch switch-sm switch-primary">
|
||||
<input type="checkbox" name="user"><span></span> Пользователи
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label class="css-input switch switch-sm switch-primary">
|
||||
<input type="checkbox" name="demo"><span></span> Демо-пользователи
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="form-group m-b-0">
|
||||
<div class="col-sm-9">
|
||||
<button class="btn btn-app" type="submit">Запустить</button>
|
||||
<button class="btn btn-app" type="submit">Запустить рассылку</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Reference in new issue
Block a user