|
@@ -11,6 +11,8 @@
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
namespace App\Services;
|
|
|
use app\Lib\smtpMail\smtp as smtpService;
|
|
use app\Lib\smtpMail\smtp as smtpService;
|
|
|
|
|
+use Illuminate\Mail\Mailable;
|
|
|
|
|
+use Illuminate\Support\Facades\Mail;
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -45,6 +47,8 @@ class EmailService extends BaseService
|
|
|
$smtp['username'] = isset($config['mail_username']['value']) && $config['mail_username']['value'] ? $config['mail_username']['value'] : $smtp['host'];
|
|
$smtp['username'] = isset($config['mail_username']['value']) && $config['mail_username']['value'] ? $config['mail_username']['value'] : $smtp['host'];
|
|
|
$smtp['password'] = isset($config['mail_password']['value']) && $config['mail_password']['value'] ? $config['mail_password']['value'] : $smtp['password'];
|
|
$smtp['password'] = isset($config['mail_password']['value']) && $config['mail_password']['value'] ? $config['mail_password']['value'] : $smtp['password'];
|
|
|
$smtp['timeout'] = isset($config['mail_timeout']['value']) && $config['mail_timeout']['value'] ? $config['mail_timeout']['value'] : $smtp['timeout'];
|
|
$smtp['timeout'] = isset($config['mail_timeout']['value']) && $config['mail_timeout']['value'] ? $config['mail_timeout']['value'] : $smtp['timeout'];
|
|
|
|
|
+ $smtp['encryption'] = isset($config['mail_source']['value']) && $config['mail_source']['value'] ? $config['mail_source']['value'] : $smtp['encryption'];
|
|
|
|
|
+ $smtp['timeout'] = 10;
|
|
|
if ($mail['default'] != 'smtp') {
|
|
if ($mail['default'] != 'smtp') {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -84,8 +88,20 @@ class EmailService extends BaseService
|
|
|
$code = rand(100000, 999999);
|
|
$code = rand(100000, 999999);
|
|
|
$template = str_replace('{code}', $code, $template);
|
|
$template = str_replace('{code}', $code, $template);
|
|
|
|
|
|
|
|
|
|
+ var_dump($this->config);
|
|
|
|
|
+ Mail::send('emails.index',['title'=> $title,'template'=> $template], function($mail) use($email, $template){
|
|
|
|
|
+ $mail->from($this->config['username'],'UTC');
|
|
|
|
|
+ $mail->subject($template);
|
|
|
|
|
+ $mail->to($email);
|
|
|
|
|
+ });
|
|
|
|
|
+ $error = Mail::failures();
|
|
|
|
|
+ if (!$error) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+
|
|
|
// 邮件服务
|
|
// 邮件服务
|
|
|
-var_dump($this->config);
|
|
|
|
|
$mail = new PHPMailer(true);
|
|
$mail = new PHPMailer(true);
|
|
|
$mail->CharSet ="UTF-8"; //设定邮件编码
|
|
$mail->CharSet ="UTF-8"; //设定邮件编码
|
|
|
$mail->SMTPDebug = 0; //调试模式输出:0 不输出,2 输出
|
|
$mail->SMTPDebug = 0; //调试模式输出:0 不输出,2 输出
|
|
@@ -96,7 +112,7 @@ var_dump($this->config);
|
|
|
$mail->SMTPAuth = true; // 允许 SMTP 认证
|
|
$mail->SMTPAuth = true; // 允许 SMTP 认证
|
|
|
$mail->Username = $this->config['username']; // SMTP用户名: 即发送方的邮箱
|
|
$mail->Username = $this->config['username']; // SMTP用户名: 即发送方的邮箱
|
|
|
$mail->Password = $this->config['password']; // SMTP授权码: 即发送方的邮箱授权码
|
|
$mail->Password = $this->config['password']; // SMTP授权码: 即发送方的邮箱授权码
|
|
|
- $mail->SMTPSecure = isset($this->config['mail_source'])? $this->config['mail_source'] : 'tls'; // 允许 TLS 或者ssl协议
|
|
|
|
|
|
|
+ $mail->SMTPSecure = isset($this->config['mail_source']['value'])? $this->config['mail_source']['value'] : 'tls'; // 允许 TLS 或者ssl协议
|
|
|
$mail->Port = $this->config['port']; // 服务器端口: 25 或者465 或者587 具体要看邮箱服务器支持
|
|
$mail->Port = $this->config['port']; // 服务器端口: 25 或者465 或者587 具体要看邮箱服务器支持
|
|
|
|
|
|
|
|
RedisService::set('mailer', $this->config, 600);
|
|
RedisService::set('mailer', $this->config, 600);
|