Introduction to how to use 163 mailbox to send emails in laravel5.4

黄舟
Release: 2023-03-16 10:50:02
Original
2077 people have browsed it

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.

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


##The authorization code is very important. Please remember it carefully. You will configure it in laravel’s .env later~~


2. If you have done all the above, then the next step is to configure .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
Copy after login

3. Then continue The next step is to configure routing and write the method of sending emails on the controller


Route::get('mail/send','CommonController@send');
Copy after login

Write this on any controller you want send method:



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 '发送邮件失败,请重试!'; // } }
Copy after login

Okay, the next step is to access the routing yourself to get the results you want~~~~~

PS:The key point is to get the error reporting process right. Basically, if you follow the steps, there won’t be any big problems. However, the most important thing is what I use. It is done on Ubuntu16.04 system. The permission issues should be solved first, so I suggest giving permission first and opening the command line in your directory:sudo chmod 777 -R ./

Okay, the next step is to solve the problem of not being able to connect to the 163 NetEase mailbox. The method I can give is to add two lines of code to line 263 of StreamBuffer.php:



$options['ssl']['verify_peer'] = FALSE; $options['ssl']['verify_peer_name'] = FALSE;
Copy after login

Basically follow the above steps and you can get it done~~~

Summary

The above is the detailed content of Introduction to how to use 163 mailbox to send emails in laravel5.4. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!