EIOS/inc/email_cron.php

100 lines
3.5 KiB
PHP

<?php
//Таблица: acs_emails_cron:
// id int(11),
// data_c int(11),
// data_u int(11),
// title text,
// message text,
// toemail varchar(255),
// ot_from varchar(255),
// ff int(11),
// tpl varchar(255),
// md5 text,
// kol int(11),
// errors longtext
//error:
// {"time":1697202006,"error":"SMTP connect() failed. https:\/\/github.com\/PHPMailer\/PHPMailer\/wiki\/Troubleshooting"}
// {"time":1697202236,"error":"SMTP connect() failed. https:\/\/github.com\/PHPMailer\/PHPMailer\/wiki\/Troubleshooting"}
// {"time":1697202464,"error":"SMTP connect() failed. https:\/\/github.com\/PHPMailer\/PHPMailer\/wiki\/Troubleshooting"}
// {"time":1697202505,"error":"SMTP connect() failed. https:\/\/github.com\/PHPMailer\/PHPMailer\/wiki\/Troubleshooting"}
// {"time":1697203883,"error":"SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: Message rejected under suspicion of SPAM; https:\/\/ya.cc\/1IrBc 1697203883-NVg3uY5DY0U0-FvqUIWd1\r\n SMTP code: 554 Additional SMTP info: 5.7.1"}
// {"time":1697203895,"error":"SMTP connect() failed. https:\/\/github.com\/PHPMailer\/PHPMailer\/wiki\/Troubleshooting"}
/**
* Сохранение письма при ошибке отправки
* @param $param
* @return void
*/
function EMAIL_cron_save_task($param){
GLOBAL $ST,$DB;
$title = $param['title'];
$message = $param['message'];
$toemail = $param['toemail'];
$ot_from = $param['from'];
$ff = $param['f'];
$tpl = $param['tpl'];
$md5 = EMAIL_cron_md5create($param);
$error = array('time'=>time(),'error'=>$param['error']);
$isset = EMAIL_cron_check($md5);
if(!count($isset)) {
$sql = 'INSERT INTO acs_emails_cron VALUES(0,' . time() . ',' . time() . ',"' . $DB->rescape($title) . '","' . $DB->rescape($message) . '","' . $DB->rescape($toemail) . '","' . $DB->rescape($ot_from) . '",' . $ff . ',"' . $DB->rescape($tpl) . '","' . $md5 . '",1,"' . $DB->rescape(json_encode($error, JSON_UNESCAPED_UNICODE)) . '")';
$DB->QUR($sql);
}else{//обновим данные
$id = $isset['id'];
$kol = $isset['kol']+1;
$error1 = json_decode($isset['error'],1);
$error1 = array_merge($error1,$error);
$sql = 'UPDATE acs_emails_cron SET data_u=' . time() . ',kol=' . $kol . ',error="'.$DB->rescape(json_encode($error1, JSON_UNESCAPED_UNICODE)).'" WHERE id='.$id;
$DB->QUR($sql);
}
}
/**
* Удаление задачи из отправки писем
* @param $param
* @return array
*/
function EMAIL_cron_dele_task($param){
GLOBAL $ST,$DB; $out = array();
$md5 = EMAIL_cron_md5create($param);
$isset = EMAIL_cron_check($md5);
if(count($isset)) {
$id = $isset['id'];
$sql = 'DELETE FROM acs_emails_cron WHERE id='.$id;
$DB->QUR($sql);
}
return $out;
}
/**
* Создаем MD5 письма
* @param $param
* @return string
*/
function EMAIL_cron_md5create($param){
$title = $param['title'];
$message = $param['message'];
$toemail = $param['toemail'];
$ot_from = $param['from'];
$ff = $param['f'];
$tpl = $param['tpl'];
return md5($title.$message.$toemail.$ot_from.$ff.$tpl);
}
/**
* Проверка на существование такого письма
* @param $md5
* @return array|mixed
*/
function EMAIL_cron_check($md5){
GLOBAL $ST,$DB; $out = array();
$sql = 'SELECT id,error,kol FROM acs_emails_cron WHERE md5="'.$md5.'"';
$rez = $DB->QUR_SEL($sql);
if($rez){
$out = $rez[1];
}
return $out;
}