简单粗暴,直接上代码!
.env:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com
MAIL_PORT=465
MAIL_USERNAME=route@163.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
控制器层:
//163邮箱发送邮件
public function mail(){
$data=Crty::mailed();
// print_r($data);die;
Mail::send("add_sort/shows",['user'=>$data->user],function($message){
$message->from("15******97@163.com","发件人");
$message->subject('message');
$message->to('收件人@qq.com');
});
}
//缓存Cache
public function register(Request $request){
if($request->isMethod('post')){
$data=$request->all();
$info=Crty::registered($data);
// print_r($info);die;
if($info){
return redirect('crty/mail');
}
}elseif($request->isMethod('get')){
return view('add_sort/register');
}
}
model层:
//注册model
public static function registered($data){
// print_r($data);die;
if(empty($data['user'])){
echo "用户名不能为空";die;
}
if(empty($data['pwd'])){
echo "密码不能为空";die;
}
if(empty($data['telphone'])){
echo "手机号码不能为空";die;
}
if(empty($data['email'])){
echo "邮箱不能为空";die;
}
$user=$data['user'];
$telphone=$data['telphone'];
$email=$data['email'];
$arr=array(
'user'=>$data['user'],
'pwd'=>$data['pwd'],
'telphone'=>$data['telphone'],
'email'=>$data['email']
);
Mail::send("add_sort/shows",['user'=>$arr['user'],'telphone'=>$arr['telphone']],function($message){
$message->from("1**105****7@163.com","发件人");
$message->subject('message');
$message->to('11****@qq.com');
});
//设置缓存,用以想客户发送邮箱数据
$insert=DB::table('register')->insert($arr);
return $insert;
}
//邮箱验证
public static function mailed(){
$data=DB::table('register')->where('id',25)->first();
return $data;
}
view:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table>
<tr>
<td>恭喜{{$user}},用户电话{{$telphone}}</td>
</tr>
</table>
</body>
</html>