Home > Backend Development > PHP Tutorial > Detailed explanation of laravel5.4 using 163 mailbox to send emails

Detailed explanation of laravel5.4 using 163 mailbox to send emails

*文
Release: 2023-03-19 08:44:01
Original
1899 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. 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


##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 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
Copy after login

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');
Copy after login

Just write this send method on any controller:

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 route yourself and you will be able to get it. The desired result~~~~~

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 ./

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 line 263 of StreamBuffer.php Add two lines of code:

$options['ssl']['verify_peer'] = FALSE;

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

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

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!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template