Step 1:
Generate a mail sending object
php artisan make:mail TestMail
Step 2:
Edit .env
to add/modify (if there is no key, add)
MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com (163 mailbox is used here)
MAIL_PORT=25 (163 mailbox port is 25)
MAIL_USERNAME=xxx@163. com (user name of 163 mailbox)
MAIL_PASSWORD=FEHRTFDFKAJGZDKP (open smtp service in 163 mailbox by yourself, see the picture below)
MAIL_ENCRYPTION=null (ignore)
[email protected] (163 mailbox user name)
MAIL_FROM_NAME=aabcc (fill in whatever)
Step 3:
Edit config/mail.php
to add/modify (no additions)
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', '随便填个'),
],
'to' => [
'address' => '[email protected]', // 接收人的邮箱
'name' => '随便填个'
],
Step 4:
Create a new blade file in resources/views, with any content, just fill in helloworld.
Reference to the directory after creation: resources/views/mytest.blade.php
Step 5:
Edit the app/Mail/TestMail.php file generated in the first step
and modify the build method to:
public function build()
{
return $this->view('mytest');
}
Step 6:
Mail sending
Illuminate\Support\Facades\Mail::send(new TestMail);
OK! ! ! ! ! So far, the email has been successfully sent!