[+] реализован функционал отправки писем через очередь
This commit is contained in:
1 parent
10e1b7eaa5
commit
24d0281ffa
3 files changed
+63
-15
No files matched your search
@@ -226,20 +226,29 @@
|
||||
*/
|
||||
public function sendMail(): void
|
||||
{
|
||||
$mailObject = new Mail();
|
||||
$mailTo = $this->request->getProperty('to');
|
||||
$mailSubject = $this->request->getProperty('subject');
|
||||
$mailBody = $this->request->getProperty('body');
|
||||
$mailTemplate = $this->request->getProperty('template');
|
||||
$mailFrom = 'noreply@it-stories.ru';
|
||||
$result = $mailObject->setTo($mailTo, 'user')
|
||||
->setFrom($mailFrom, 'Info System')
|
||||
->setTemplate($mailTemplate ?: MAIL_TEMPLATE_DEFAULT)
|
||||
->setTemplateVars(['TITLE' => $mailSubject])
|
||||
->setSubject($mailSubject)
|
||||
->setBody($mailBody)
|
||||
->send();
|
||||
ApiView::output(['result' => $result]);
|
||||
$responseObject = (new MQ())->setPriority(7)
|
||||
->setAttempts(2)
|
||||
->createTask('Core\MQTasks',
|
||||
'sendMail',
|
||||
[
|
||||
SERVER_EMAIL,
|
||||
SERVER_EMAIL_NAME,
|
||||
$this->request->getProperty('to'),
|
||||
null,
|
||||
$this->request->getProperty('subject'),
|
||||
$this->request->getProperty('body'),
|
||||
MAIL_TEMPLATE_DEFAULT,
|
||||
['TITLE' => $this->request->getProperty('subject')],
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
ApiView::output(
|
||||
[
|
||||
'status' => $responseObject->getStatus(),
|
||||
'response' => $responseObject->getResponse(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@
|
||||
];
|
||||
foreach ($keys as $key) {
|
||||
if (!empty($_SERVER[$key])) {
|
||||
$ip = trim(end(explode(',', $_SERVER[$key])));
|
||||
$arData = explode(',', $_SERVER[$key]);
|
||||
$ip = trim(end($arData));
|
||||
if (filter_var($ip, FILTER_VALIDATE_IP)) {
|
||||
return $ip;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
namespace Core;
|
||||
|
||||
use Core\Helpers\Cache;
|
||||
use Core\Helpers\Mail;
|
||||
use Core\Helpers\SystemFunctions;
|
||||
use Core\Helpers\Thumbs;
|
||||
use Core\ExternalServices\TelegramSender;
|
||||
@@ -458,4 +459,41 @@ DELETE from `jokes` WHERE `jokes`.id not in (SELECT id FROM t_temp);'
|
||||
return 'Добавлено постов: ' . count($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Отправка E-Mail
|
||||
*
|
||||
* @param string $fromMail E-Mail отправителя
|
||||
* @param string|null $fromName Имя отправителя
|
||||
* @param string $toMail E-Mail получателя
|
||||
* @param string|null $toName Имя получателя
|
||||
* @param string $subject Тема письма
|
||||
* @param string $body Тело письма
|
||||
* @param string|null $template Шаблон
|
||||
* @param array|null $templateVars Переменные шаблона
|
||||
*
|
||||
* @return array
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static function sendMail(
|
||||
string $fromMail,
|
||||
?string $fromName,
|
||||
string $toMail,
|
||||
?string $toName,
|
||||
string $subject,
|
||||
string $body,
|
||||
?string $template = null,
|
||||
?array $templateVars = null
|
||||
): array {
|
||||
$mailObject = new Mail();
|
||||
$mailObject->setTo($toMail, $toName)
|
||||
->setFrom($fromMail, $fromName)
|
||||
->setSubject($subject)->setBody($body);
|
||||
if ($template !== null && $templateVars !== null) {
|
||||
$mailObject->setTemplate($template)
|
||||
->setTemplateVars($templateVars);
|
||||
}
|
||||
|
||||
return $mailObject->send();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user