You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.7 KiB
53 lines
1.7 KiB
2 months ago
|
<?php
|
||
|
|
||
|
namespace app\utility;
|
||
|
|
||
|
use PHPMailer\PHPMailer\Exception;
|
||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||
|
class SendEmail
|
||
|
{
|
||
|
|
||
|
private $phpEmail;
|
||
|
public function __construct()
|
||
|
{
|
||
|
$this->phpEmail = new PHPMailer();
|
||
|
$this->phpEmail->SMTPDebug = 0; // 关闭调试功能
|
||
|
$this->phpEmail->CharSet = 'UTF-8';
|
||
|
$this->phpEmail->isSMTP(); // 设定使用SMTP服务
|
||
|
//$this->phpEmail->Host = 'smtpdm-ap-southeast-1.aliyun.com';
|
||
|
$this->phpEmail->Host = empty( env('EMAIL.Host')) ? 'smtpdm-ap-southeast-1.aliyun.com': env('EMAIL.Host');
|
||
|
$this->phpEmail->Port = 465; // SMTP服务器的端口号
|
||
|
$this->phpEmail->SMTPAuth = true;
|
||
|
$this->phpEmail->Username = env('EMAIL.Username'); // 发件地址
|
||
|
$this->phpEmail->Password = env('EMAIL.Password'); // SMTP密码
|
||
|
$this->phpEmail->SMTPSecure = 'ssl';
|
||
|
$this->phpEmail->From = env('EMAIL.From');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @desc 发送邮箱服务
|
||
|
* @param $toAddress // 收件地址
|
||
|
* @param $title // 标题
|
||
|
* @param $content // 内容
|
||
|
* @return bool
|
||
|
*/
|
||
|
public function sendEmail($toAddress, $title, $content): bool
|
||
|
{
|
||
|
try {
|
||
|
$this->phpEmail->addAddress($toAddress);
|
||
|
$this->phpEmail->Subject = $title;
|
||
|
$this->phpEmail->Body = $content;
|
||
|
$status = $this->phpEmail->send();
|
||
|
if ($status) {
|
||
|
return true;
|
||
|
}
|
||
|
trace('---异常-----'.$this->phpEmail->ErrorInfo, 'info');
|
||
|
|
||
|
return false;
|
||
|
}catch (\Exception $exception) {
|
||
|
trace('---异常-----'.$exception->getMessage(), 'info');
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|