简体   繁体   English

电子邮件未在Laravel 5.4中使用Smtp发送

[英]Email not send using Smtp in laravel 5.4

i want to send an email to forgot password function congaing new password. 我想发送一封电子邮件以忘记新的密码功能。 Here is my code, 这是我的代码,

MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=offrs
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls

here is my function for sending mail 这是我发送邮件的功能

  public function sendMail(Request $request){
        $new_key = str_random(10);
        $data = array();
        $data['email'] = $request->email;
        $data['key'] = $new_key;
        $checkUser = User::where('email','=',$request->email)->first();
        if($checkUser == null){
            return redirect()->back()->with('error','No User with this email exists in our record');
        }
        else{
            Mail::send('mail.forgetPasswordMail', ['data' => $data], function ($message) use ($data) {
                $message->from('raiafaculty@domain.com', 'RAIA Admin');
                $message->to(Input::get('email'))->subject('Your New Password');
            });
//            $useremail = $request->get('email');
//            $user = User::where('email', '=', $useremail)->first();
            $checkUser->password = bcrypt($new_key);
            $checkUser->save();

            return redirect()->route('login')->with('success','Please Check Your email for new password');
        }
    }

it produces the error always. 它总是产生错误。 (1/1) Swift_TransportException Connection could not be established with host smtp.sendgrid.net [No connection could be made because the target machine actively refused it. (1/1)Swift_TransportException无法与主机smtp.sendgrid.net建立连接[无法建立连接,因为目标计算机主动拒绝了连接。

10061] 10061]

at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'tcp', 'host' => 'smtp.sendgrid.net', 'port' => 587, 'timeout' => 30, 'blocking' => 1, 'tls' => true, 'type' => 1, 'stream_context_options' => array())) in AbstractSmtpTransport.php (line 113) 在Swift_Transport_StreamBuffer-> initialize(array('protocol'=>'tcp','host'=>'smtp.sendgrid.net','port'=> 587,'timeout'=> 30,'blocking'=> 1 ,'tls'=> true,'type'=> 1,'stream_context_options'=> array()))在AbstractSmtpTransport.php(第113行)

Help will be appreciated please. 帮助将不胜感激。

在下面更改您的代码

MAIL_ENCRYPTION=null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM