1、新增 或 编辑.env文件
MAIL_DRIVER=smtp
MAIL_HOST=smtp.qq.com
MAIL_PORT=465
MAIL_PASSWORD=(此处是获取授权码)
MAIL_ENCRYPTION=ssl
MAIL_FROM_NAME=SuperGu
注意:MAIL_USERNAME 与 MAIL_FROM_ADDRESS 邮箱需要保持一致,否则报错:Expected response code 250 but got code "501", with message "501 mail from address must be same as authorization user "
Demo:
1、控制器文件
useIlluminate\Support\Facades\Mail;
try{
$name = '测试邮件发送';
$desc = '这是一封测试邮件';
Mail::send('email.send', ['name' => $name, 'desc' => $desc],function($message) {
$to = 'xxx@qq.com';
$message->to($to)->subject('邮件推送');
});
if(count(Mail::failures()) < 1) {
Mail::raw('邮件推送成功,请注意查收!',function($message) {
$to = 'xxx@qq.com';
$message->to($to)->subject('success推送成功,请注意查收');
});
$msg = '发送邮件成功,请查收!';
}else{
$msg = '发送邮件失败,请重试!';
}
}catch(\Exception $exception) {
$exception->getMessage();
}
2、视图文件 /resources/views/email/send.blade.php
(html内容随便写,测试即可)
网友评论