diff --git a/public/tests/hook.php b/public/tests/hook.php index 7efe38a8..c408fbe7 100644 --- a/public/tests/hook.php +++ b/public/tests/hook.php @@ -89,6 +89,8 @@ $oHttp->aData['message']['text'] = '\/coupon#del 11'; $oHttp->aData['message']['text'] = '\/user#limit 10'; +$oHttp->aData['message']['text'] = '/mail#tmp'; + //$oHttp->aData['message']['text'] = '\/coupon#findById 3'; diff --git a/src/Controllers/TestController.php b/src/Controllers/TestController.php index fd90799f..909980d3 100755 --- a/src/Controllers/TestController.php +++ b/src/Controllers/TestController.php @@ -82,8 +82,10 @@ final class TestController extends BaseController public function test2() { $oCron = new CronService(); + $oCron->processEmailQueue(); + // $oCron->expirePaidUserAccount(); - $oCron->expireFreeUserAccount(); +// $oCron->expireFreeUserAccount(); } diff --git a/src/Models/EmailQueue.php b/src/Models/EmailQueue.php index 38bebb2a..53b7b4e4 100755 --- a/src/Models/EmailQueue.php +++ b/src/Models/EmailQueue.php @@ -32,4 +32,15 @@ final class EmailQueue extends Model $this->array = json_encode($array); $this->save(); } + + public function add_bulk($to, $subject, $template, $array): void + { + $this->to_email = $to; + $this->subject = $subject; + $this->template = $template; + $this->time = time(); + $this->array = json_encode($array); + $this->type = "bulk"; + $this->save(); + } } diff --git a/src/Services/Cron.php b/src/Services/Cron.php index c332f31c..80456beb 100755 --- a/src/Services/Cron.php +++ b/src/Services/Cron.php @@ -452,12 +452,23 @@ final class Cron if (Tools::isEmail($email_queue['to_email'])) { try { - Mail::send( - $email_queue['to_email'], - $email_queue['subject'], - $email_queue['template'], - json_decode($email_queue['array']) - ); + + if (isset($email_queue['type']) && $email_queue['type'] == "bulk") { + Mail::send_bulk( + $email_queue['to_email'], + $email_queue['subject'], + $email_queue['template'], + json_decode($email_queue['array']) + ); + } else { + Mail::send( + $email_queue['to_email'], + $email_queue['subject'], + $email_queue['template'], + json_decode($email_queue['array']) + ); + } + } catch (Exception|ClientExceptionInterface $e) { echo $e->getMessage(); } diff --git a/src/Services/Mail.php b/src/Services/Mail.php index af0dca70..44f1f0d4 100755 --- a/src/Services/Mail.php +++ b/src/Services/Mail.php @@ -13,6 +13,7 @@ use App\Services\Mail\Postal; use App\Services\Mail\SendGrid; use App\Services\Mail\Ses; use App\Services\Mail\Smtp; +use App\Services\Mail\Smtp_bulk; use Exception; use Psr\Http\Client\ClientExceptionInterface; use Smarty\Smarty; @@ -64,4 +65,11 @@ final class Mail self::getClient()->send($to, $subject, $body); } + + public static function send_bulk($to, $subject, $template, $array = []): void + { + $body = self::genHtml($template, $array); + + new Smtp_bulk()->send($to, $subject, $body); + } } diff --git a/src/Services/Mail/Smtp_bulk.php b/src/Services/Mail/Smtp_bulk.php new file mode 100755 index 00000000..32679dc8 --- /dev/null +++ b/src/Services/Mail/Smtp_bulk.php @@ -0,0 +1,60 @@ +isSMTP(); + $mail->Host = $configs['smtp_host']; + $mail->Port = $configs['smtp_port']; + $mail->SMTPAuth = ! ($configs['smtp_username'] === '' && $configs['smtp_password'] === ''); + $mail->CharSet = 'UTF-8'; + $mail->Username = $configs['smtp_username']; + $mail->Password = $configs['smtp_password']; + $mail->setFrom($configs['smtp_sender'], $configs['smtp_name']); + + if ($configs['smtp_ssl']) { + $mail->SMTPSecure = ($configs['smtp_port'] === '587' ? 'tls' : 'ssl'); + } + + if ($configs['smtp_bbc'] !== '') { + $mail->addBCC($configs['smtp_bbc']); + } + var_dump($configs); + exit; + $this->mail = $mail; + } + + /** + * @throws Exception + */ + public function send($to, $subject, $body): void + { + $mail = $this->mail; + $mail->addAddress($to); // Add a recipient + $mail->isHTML(); + $mail->Subject = $subject; + $mail->Body = $body; + + $mail->send(); + } +} diff --git a/src/Services/Tg/Hook/Mod/Email.php b/src/Services/Tg/Hook/Mod/Email.php deleted file mode 100644 index cf0ff928..00000000 --- a/src/Services/Tg/Hook/Mod/Email.php +++ /dev/null @@ -1,60 +0,0 @@ -主域名fuuu.cloud被封禁,已更换为fuuuu.cloud(多一个u)。"; - - $content = strip_tags( - str_replace( - ['

','

'], - ['','

'], - $text - ), - ['br', 'a', 'strong'] - ); - -// $users = (new User())->where('class', '>=', 0) -// ->get(); - - $users = (new User())->where("email", "yuejiqi@tuta.io")->get(); - - foreach ($users as $user) { - (new EmailQueue())->add( - $user->email, - $subject, - 'war.tpl', - [ - 'user' => $user, - 'text' => $content, - ] - ); - } - - - return "应该发送成功了"; - - - - - } - -} diff --git a/src/Services/Tg/Hook/Mod/Mail.php b/src/Services/Tg/Hook/Mod/Mail.php new file mode 100644 index 00000000..ddfb489e --- /dev/null +++ b/src/Services/Tg/Hook/Mod/Mail.php @@ -0,0 +1,121 @@ +主域名fuuu.cloud被封禁,已更换为fuuuu.cloud(多一个u)。"; + + $content = strip_tags( + str_replace( + ['

','

'], + ['','

'], + $text + ), + ['br', 'a', 'strong'] + ); + +// $users = (new User())->where('class', '>=', 0) +// ->get(); + + $users = (new User())->where("email", "yuejiqi@tuta.io")->get(); + + foreach ($users as $user) { + (new EmailQueue())->add_bulk( + $user->email, + $subject, + 'war.tpl', + [ + 'user' => $user, + 'text' => $content, + ] + ); + } + + + return "应该发送成功了"; + + + + + } + + + + + public function tmp2() + { + $subject = "福云 - 重要通知:域名地址变更!"; + + + + $text = "
主域名fuuu.cloud被封禁,已更换为fuuuu.cloud(多一个u)。"; + + $content = strip_tags( + str_replace( + ['

','

'], + ['','

'], + $text + ), + ['br', 'a', 'strong'] + ); + +// $users = (new User())->where('class', '>=', 0) +// ->get(); + + $users = (new User())->where("email", "yuejiqi@tuta.io")->get(); + + foreach ($users as $user) { + (new EmailQueue())->add( + $user->email, + $subject, + 'war.tpl', + [ + 'user' => $user, + 'text' => $content, + ] + ); + } + + + return "应该发送成功了"; + + + + + } + + + + +}