当前位置:网站首页>Send email to laravel

Send email to laravel

2022-04-23 20:43:00 Chen qingnuo language

laravel  Core points of email sending : Need to use Mail object  

1、 First, configure... In the mailbox : Turn on 【POP3/SMTP service 】

Generate the key

2、 stay .env Middle configuration

MAIL_MAILER=smtp
MAIL_HOST=smtp.qq.com
MAIL_PORT=465
[email protected]// Your email account 
MAIL_PASSWORD=// Turn on qq mailbox SMTP The authorization password obtained after 
MAIL_ENCRYPTION=ssl
[email protected]// Your email account 
MAIL_FROM_NAME="${APP_NAME}"


3、 Operate in the controller : introduce Mail object

use Illuminate\Support\Facades\Mail;


4、 Add mail sending method :

// Direct text sending 
 Mail::raw(' Test mail ',function ($message){
            $message->from('[email protected]// Your email account ',' Test mail ');
            $message->subject('hhhhhhhh');
            $message->to('[email protected]// Your email account ');
        });
        $qq = '[email protected]// Your email account ';


// Use blade Template send ( Referenced template )
 Mail::send('mailtest',['name' => 'test'],function($message)use($qq){
            $message->to($qq)->subject('hhhhhhh');
        });


5、 If you use blade Template send , You need to add the corresponding blade Templates , For example, in /view Add under directory mailtest.blade.php Templates

<p>hello {
   {$name}}</p>

版权声明
本文为[Chen qingnuo language]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232042380674.html