2021-02-04 23:36:14 +08:00
|
|
|
<?php
|
2021-09-04 20:18:20 +08:00
|
|
|
declare(strict_types=1);
|
2021-02-04 23:36:14 +08:00
|
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
|
2021-09-11 15:53:23 +08:00
|
|
|
use App\Support\Mailer;
|
2021-02-04 23:36:14 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class MailerService
|
2021-04-20 16:30:57 +08:00
|
|
|
*
|
2021-02-04 23:36:14 +08:00
|
|
|
* @package App\Service
|
|
|
|
*/
|
|
|
|
class MailerService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 消息队列
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $queueSwitch = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 发送邮件
|
|
|
|
*
|
2021-04-20 16:30:57 +08:00
|
|
|
* @param string $email 邮箱
|
|
|
|
* @param string $subject 标题
|
2021-02-04 23:36:14 +08:00
|
|
|
* @param string $template 对应邮件模板
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-09-04 20:18:20 +08:00
|
|
|
public function send(string $email, string $subject, string $template): bool
|
2021-02-04 23:36:14 +08:00
|
|
|
{
|
|
|
|
if ($this->queueSwitch) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->realSend($email, $subject, $template);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 发送邮件
|
|
|
|
*
|
2021-04-20 16:30:57 +08:00
|
|
|
* @param string $email 邮箱
|
|
|
|
* @param string $subject 标题
|
2021-02-04 23:36:14 +08:00
|
|
|
* @param string $template 对应邮件模板
|
|
|
|
* @return bool
|
|
|
|
*/
|
2021-09-04 20:18:20 +08:00
|
|
|
public function realSend(string $email, string $subject, string $template): bool
|
2021-02-04 23:36:14 +08:00
|
|
|
{
|
2021-09-11 15:53:23 +08:00
|
|
|
return $this->mail($email, $subject, $template);
|
2021-02-04 23:36:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 推送邮件
|
|
|
|
*
|
|
|
|
* @param string $address 收件人
|
|
|
|
* @param string $subject 邮件标题
|
2021-04-20 16:30:57 +08:00
|
|
|
* @param string $view 邮件内容
|
2021-02-04 23:36:14 +08:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function mail(string $address, string $subject, string $view): bool
|
|
|
|
{
|
2021-09-11 15:53:23 +08:00
|
|
|
return di()->get(Mailer::class)->send($address, $subject, $view);
|
2021-02-04 23:36:14 +08:00
|
|
|
}
|
|
|
|
}
|