Sending emails is an essential requirement that we encounter in daily development. The following article mainly introduces you to the steps of using laravel5.4 to send emails using the 163 mailbox. The article introduces it through sample codes and pictures. Very detailed, friends in need can refer to it. I hope to be helpful.
Preface
In fact, sending an email is not difficult, rather it is quite simple. This article will introduce in detail about laravel5.4 using 163 email to send The relevant content of the email is shared for everyone’s reference and study. I won’t go into details below, let’s take a look at the detailed introduction.
1. First, register an account with 163 now and set it up as shown below
2. If you have done all the above, then the next step is to configure the .env
MAIL_DRIVER=smtp MAIL_HOST=smtp.163.com MAIL_PORT=465 MAIL_USERNAME=你的账号@163.com MAIL_PASSWORD=你的客户端授权密码 MAIL_FROM_ADDRESS=你的账号@163.com MAIL_FROM_NAME=账号名 MAIL_ENCRYPTION=ssl
3. Then the next step is to configure routing and write and send emails on the controller The method
Route::get('mail/send','CommonController@send');
public function send() { $name='学院君'; $flag= Mail::raw('你好,我是PHP程序!',function($message) { $to='你的qq邮箱@qq.com'; $message->to($to)->subject('纯文本信息邮件测试'); }); if(!$flag){ echo '发送邮件成功,请查收!'; }else{ echo '发送邮件失败,请重试!'; } //以上是纯文本,下面则是附带文件发送 // $flag = Mail::send('emails.test',['name'=>$name],function($message){ // $to = '你的qq邮箱@qq.com'; // $message->to($to)->subject('text'); // // $filePath = 'storage/exports/'.iconv('UTF-8', 'GBK', '学生成绩').'.xls'; // $attachment = storage_path('app/files/test.txt'); // //在邮件中上传附件 // $message->attach($attachment,['as'=>'text.txt']); // }); //下面是发送邮件附带图片的 // $imgPath = 'http://laravelacademy.org/wp-statics/images/carousel/LaravelAcademy.jpg'; // $flag = Mail::send('emails.test',['name'=>$name,'imgPath'=>$imgPath],function($message){ // $to = '你的qq邮箱@qq.com'; // $message ->to($to)->subject('网络图片测试'); // }); // if(!$flag){ // echo '发送邮件成功,请查收!'; // }else{ // echo '发送邮件失败,请重试!'; // } }
PS:The key point is to get the error reporting process. Basically, if you follow the steps, nothing will happen. It's a big problem, but the most important thing is that I used Ubuntu16.04 system to do it. The permission problem should be solved first, so I suggest giving permission first and opening the command line in your directory. :sudo chmod 777 -R ./
$options['ssl']['verify_peer'] = FALSE; $options['ssl']['verify_peer_name'] = FALSE;
Related recommendations:
Detailed explanation of Laravel’s localization module
Detailed explanation of how to rewrite resource routing in Laravel
A brief analysis of Laravel’s late static binding
The above is the detailed content of Detailed explanation of laravel5.4 using 163 mailbox to send emails. For more information, please follow other related articles on the PHP Chinese website!