First, mailbox configuration
163 E-mail I used to do to send, open the mailbox must log 163 POP3 and SMTP services, and generate an authorization code.
![](https://upload-images.jianshu.io/upload_images/2526346-9773ea02055716ee.png?imageMogr2/auto-orient/strip|imageView2/2/w/330/format/webp)
After opening the SMTP service, you also need authorization to open and set the password.
![](https://upload-images.jianshu.io/upload_images/2526346-833b0eb59865fc2e.png?imageMogr2/auto-orient/strip|imageView2/2/w/629/format/webp)
Two, Laravel configuration
Only you need to configure .env can be.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com MAIL_PORT=465 MAIL_USERNAME=你的163邮箱地址 MAIL_PASSWORD=你的163邮箱地址对应的授权密码(不是登录密码)| 腾讯企业邮是邮箱密码 MAIL_ENCRYPTION=ssl | 腾讯企业邮是tls MAIL_FROM_ADDRESS="你的163邮箱地址 | 腾讯企业邮是需要这项和MAIL_USERNAME一模一样的" MAIL_FROM_NAME="你期望的发件人名称"
Port 465 is used ssl; MAIL_ENCRYPTION not fill it, the port is 25; note MAIL_PASSWORD is authorized password, not the password!
E.g:
Third, coding
Create a call or send a message in need of controller, which need to send e-mail function adds:
use Illuminate\Support\Facades\Mail; // 在函数内,例如post获得email地址之后调用: $message = 'test'; $to = '你需要发送的邮箱地址'; $subject = '邮件名称'; Mail::send( 'emails.test', ['content' => $message], function ($message) use($to, $subject) { $message->to($to)->subject($subject); } );
例如:
![](https://img2018.cnblogs.com/blog/1033667/201909/1033667-20190927182155453-851659784.png)
The first parameter is the blade emails.test file in view, for displaying the message content; the second parameter is a variable passed to view files; third parameter is the closure function to configure the message recipient address and name Wait.
New File: ./ resources / views / emails / test.blade.php
E.g:
![](https://img2018.cnblogs.com/blog/1033667/201909/1033667-20190927182114898-1134392408.png)