laravel5.3 Send E-mail

Ready to work

  • Abstract: This paper describes the use laravel send mail flow and pit
  • Send e-mail: E-mail is best to give qq qq-mail sent, if 163 E-mail address to send mail qq, qq-mail will be treated as spam, if small partners successfully sent, did not receive the message, go to spam in review it.
1, to prepare 163 mailboxes, mailbox configuration modifications 163
  1. 163 E-mail open smtp, obtain authorization code:
    Here Insert Picture Description
    Here Insert Picture Description
2, laravel mail configuration
  1. Mail.php open the config configuration file
 'from' => [
        'address' => env('MAIL_USERNAME', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
    address:填写.env配置文件里面的MAIL_FROM_NAME
    name: 填写.env配置文件里面的MAIL_FROM_NAME
  1. Configuration laravel [file] .env
MAIL_DRIVER=SMTP
MAIL_HOST=smtp.163.com
MAIL_PORT=465
MAIL_USERNAME=*****163.com
MAIL_PASSWORD=授权码
MAIL_ENCRYPTION=ssl
MAIL_FROM_NAME=发件人姓名

PS:在这里需要强调一下,465端口如果用不了,则可以更换25端口尝试。
  1. Defined routing route
 //发送邮件测试
    Route::get('email','LoginController@email');
  1. This definition of controller Controller
<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;//引用邮件的类

class LoginController extends Controller
{
	public function email(){
	        //发送文字
	        Mail::raw('测试发送的内容',function($message){
	            $message->to('[email protected]');//发送地址
	            $message->subject('亲爱的用户,恭喜您注册成功');
	        });
	    }
}	    

According to the above steps, you can successfully send mail it, if there is a problem of small partners, can Comments, will be the first time I saw the reply.

Guess you like

Origin blog.csdn.net/zxh7770/article/details/90755088