第一步:config/mail.php是郵件配置文件,然后找到根目錄.env文件
MAIL_DRIVER=smtp #郵件的驅動類型,默認采用smtp MAIL_HOST= smtp.126.com #以126為例,可以到官方查看http://help.163.com/09/0219/10/52GOPOND007536NI.html MAIL_PORT=25 #官方提供接口 MAIL_USERNAME=hello_world@126.com #登陸名稱 MAIL_PASSWORD=01d333afbbcf9d3f #授權碼,以126為例,需要進入126郵件系統在設置->找到“客戶端授權密碼”->點擊獲取即可 MAIL_ENCRYPTION=null #表示加密類型,可以設置為null表示不使用任何加密,也可以設置為tls/ssl。 MAIL_FROM_ADDRESS=hello_world@126.com #您的郵件地址 MAIL_FROM_NAME=hello #名稱而已,任意
第二步:編寫純文字的郵件
Mail::Raw('Hello World', function ($message) { $message->to('8888888@qq.com')->subject('這是新郵件'); });
//Hello World 是郵件內容
//888888@qq.com是收件人的地址
第三步:編寫html的郵件
先在views新建模板文件:
<!doctype html> <html lang="{{ config('app.locale') }}"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>郵件</title> </head> <body> <div>{{$name}}</div> </body> </html>
php代碼:
Mail::send('mail.data', ['name' => 'Hello World'], function ($message) { $message->to('8888888@qq.com')->subject('您有新郵件'); });