Laravel 5.5 用自带的 SMTP 发邮件设置
邮件配置:
.env 文件设置:MAIL_PASSWORD 是客户端授权密码,不是邮件密码
MAIL_DRIVER=smtp MAIL_HOST=smtp.qq.com MAIL_PORT=465 MAIL_USERNAME=125721044@qq.com MAIL_PASSWORD=gejfjpkvzxgnca** MAIL_ENCRYPTION=ssl
app/mail.php
<?php return [ 'driver' => env('MAIL_DRIVER', 'smtp'), 'host' => env('MAIL_HOST', 'smtp.qq.com'), 'port' => env('MAIL_PORT', 465), 'from' => [ 'address' => env('MAIL_FROM_ADDRESS', '125721044@qq.com'), 'name' => env('MAIL_FROM_NAME', '小官'), ], 'encryption' => env('MAIL_ENCRYPTION', 'ssl'), 'username' => env('MAIL_USERNAME','125721044@qq.com'), 'password' => env('MAIL_PASSWORD','gejfjpkvzxgnca**'), 'sendmail' => '/usr/sbin/sendmail -bs', 'markdown' => [ 'theme' => 'default', 'paths' => [ resource_path('views/vendor/mail'), ], ], ];
/** * 发送邮件 */ public function sendMail() { $data = ['email'=>'309678100@qq.com', 'name'=>'小官','subject'=>'老大,收到微商工具提醒!','content'=>'邮件内容']; Mail::send('emails.send', $data, function($message) use($data) { $message->to($data['email'], $data['name'])->subject($data['subject']); }); }
模板 views/emails/send.blade.php
<!doctype html> <html> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> </head> <body> {{$content}} </body> </html>
如果不用模板可以如下方法
Mail::raw('邮件内容', function($message) { //指定发送人的帐号和名称 $message->from('125721044@qq.com', 'xiaoguan'); //指定邮件主题 $message->subject('主题测试'); //收件人 $message->to('309678100@qq.com'); });