laravel框架登录注册短信邮箱接口

啥话都不说了

你们先去注册一个赛邮 ,赛邮哪里有编写文档 ,

我这里就不废话了 ,

我直接上代码了,

走,

这一段是短信的接口    自己封装一个函数   

    //获取验证码
    public  function  getCode(Request $request){
            $phone = $request->input('phone');
            $code = rand(1000,9999);

            //判断 当前手机号是否被注册过
            $res = DB::table('users')->where([
                    ['phone',$phone],
                    ['state',2],
                ])->first();

            if($res){
                return 2;  //  已被注册
                die;
            }
            //引短信接口
            // return  public_path();
            require public_path().'\sdk\app_config.php';
            require_once(public_path().'\sdk\SUBMAILAutoload.php');    

            $submail=new MESSAGEXsend($message_configs);    

            $submail->setTo($phone);

            $submail->SetProject('rlkn54');                       
            $submail->AddVar('code',$code);            
            $submail->AddVar('time',60);    

            $xsend=$submail->xsend();

            if($xsend['status'] == 'success'){
                //cookie
                \Cookie::queue('code',$code,1);
                return 1;  //验证码发送成
            }else{
                return 0;  //验证码发送失败
            }
     
    }

================================================================

这里就是邮箱的接口了

 //发送邮件
    public  function  sendMail(){

        // dd(base_path());
        require base_path().'\vendor\autoload.php';

        $mail = new PHPMailer(true);                           // Passing `true` enables exceptions
        $mail->SMTPDebug = 2;                                 // Enable verbose debug output
        $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.163.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = '[email protected]';                 // SMTP username
        $mail->Password = 'zwd123456';                           // SMTP password
        $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 25;                                    // TCP port to connect to
        $mail->CharSet = "utf-8"; 
        //Recipients  接受者
        $mail->setFrom('[email protected]', '迪丽热巴');    //谁给发的

  $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = '注册';
        $code = rand(1000,9999);
        $mail->Body    = '感谢您注册官网。您的验证码是'.$code;
        // $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';  //备用信息 ,

        $res  = $mail->send();  //返回值   bool

        if($res){
            dd(1);
        }else{
            dd(0);
        }
            
        
    }

更加详细的信息   你们加我微信吧   分分钟给你解决这个问题、

那个接口的参数  赛邮上面都有文档  你们自己应该能找到

猜你喜欢

转载自blog.csdn.net/weixin_42786143/article/details/81984001