Laravel5.5 realize sending mail

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.

 
Open the settings, open SMTP

After opening the SMTP service, you also need authorization to open and set the password.

 

 
Open service and configuration authorization password

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); } );

例如:

 

 

 

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:

 

 

Guess you like

Origin www.cnblogs.com/jiangshiguo/p/11599624.html