一、安装邮件操作类
composer require phpmailer/phpmailer
二、在config中配置相关信息
//邮件发送配置
'email' => [
'Host' => 'smtp.qq.com',//SMTP服务器 以QQ邮箱为例子
'Port' => '465',//邮件发送端口
'SMTPAuth' => true,//启用SMTP认证
'SMTPSecure' => 'ssl',// 设置安全验证方式为ssl
'CharSet' => 'UTF-8',//字符集
'Encoding' => 'base64',//编码方式
'Username' => '',//你的邮箱
'Password' => '',//你的授权码
'From' => '',//发件人地址(也就是你的邮箱)
'FromName' => '',//发件人姓名
]
三、在common.php中添加公共方法
//发送邮件
if(!function_exists('sendEmail')) {
function sendEmail($data = [])
{
Vendor('phpmailer.phpmailer'); //引入扩展类文件
$mail = new \PHPMailer\PHPMailer\PHPMailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->Host = config('email.Host'); //SMTP服务器 以QQ邮箱为例子
$mail->Port = config('email.Port'); //邮件发送端口
$mail->SMTPAuth = config('email.SMTPAuth'); //