1. 在此之前先确认QQ邮箱是否开启了POP3/SMTP服务,如果未开启则须开启
QQ邮箱->设置->账户->POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务
2. 获取授权码
QQ邮箱->设置->账户->获取授权码(保存起来)
3. 在config/mail.php下配置
‘from‘ => [‘address‘ => ‘XXXXXXXX@qq.com‘, ‘name‘ => ‘Exmaple‘],
4. 在.env文件里配置邮箱信息
MAIL_DRIVER=smtp MAIL_HOST=smtp.qq.com MAIL_PORT=465 MAIL_USERNAME=XXXXXXXX@qq.com MAIL_PASSWORD=??//上面保存的授权码 MAIL_ENCRYPTION=ssl
5. 可以新建一个控制器测试一下
php artisan make:controller MailController
<?php namespace App\Http\Controllers; use Mail; class MailController extends Controller { public function send() { $name = ‘test‘; $flag = Mail::send(‘emails.test‘, [‘name‘ => $name], function($message) { $to = ‘XXXXXXXX@qq.com‘; $message->to($to)->subject(‘测试邮件‘); }); } }
路由
Route::get(‘mail/send‘,‘MailController@send‘);
emails.test 为视图, 测试随便建一个就好
=============================== over ====================================