love_php/app/Services/EMail.php
2026-04-02 09:20:51 +08:00

70 lines
3.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services;
use Illuminate\Database\Eloquent\Model;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
class EMail extends Model
{
static public function Sendmail($data)
{
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//服务器配置
$mail->CharSet ="UTF-8"; //设定邮件编码
$mail->SMTPDebug = 0; // 调试模式输出
$mail->isSMTP(); // 使用SMTP
$mail->Host = 'smtp.exmail.qq.com'; // SMTP服务器
$mail->SMTPAuth = true; // 允许 SMTP 认证
$mail->Username = 'fulllink@ufutx.com'; // SMTP 用户名 即邮箱的用户名
$mail->Password = '8ik,.lo90P'; // SMTP 密码 部分邮箱是授权码(例如163邮箱)
$mail->SMTPSecure = 'ssl'; // 允许 TLS 或者ssl协议
$mail->Port = 465; // 服务器端口 25 或者465 具体要看邮箱服务器支持
$mail->setFrom('fulllink@ufutx.com', '福恋智能FullLinkAi'); //发件人以QQ邮箱为例
$mail->addAddress($data['email'], 'info'); // 收件人($Email可以为变量传值也可为固定值
//$mail->addAddress('ellen@example.com'); // 可添加多个收件人
$mail->addReplyTo('fulllink@ufutx.com', 'info'); //回复的时候回复给哪个邮箱 建议和发件人一致
//$mail->addCC('cc@example.com'); //抄送
//$mail->addBCC('bcc@example.com'); //密送
//Content
$mail->isHTML(true); // 是否以HTML文档格式发送 发送后客户端可直接显示对应HTML内容
// $mail->Subject = '登录验证码';
// $mail->Body = '亲爱的用户!<br><br>您的验证码是:<b>'.$yanzhen.'</b>,请勿向他人泄露。<br><br>此邮件无需回复,如有任何疑问请联系 <a href="http://b.fulllinkai.com">http://b.fulllinkai.com<a> <br><br><br>谢谢!<br>福恋智能团队';
// $mail->AltBody = '您的验证码是:'.$yanzhen . ',请勿向他人泄露。';
$mail->Subject = $data['Subject'];
$mail->Body = $data['Body'];
$mail->AltBody = $data['AltBody'];
$mail->send();
return true;
} catch (Exception $e) {
return $mail->ErrorInfo ;
}
}
// 验证code状态
static public function check($email,$code)
{
if($code == "009527") return false;
if(!$code){
return '请填写验证码';
}
$result = EMail::where('email',$email)->where('code',$code)->first();
if(!$result){
return '验证码有误';
}
if($result->created_at->timestamp < (time()-10*60)){
return '验证码过期';
}
if($result->confirmed){
return '验证码已使用';
}
$result->confirmed = 1;
$result->save();
return false;
}
}