Laravel邮件错误Swift_TransportException

时间:2019-01-13 06:13:56

标签: laravel-5.6

我正在尝试使用laravel邮件制作联系表。它在localhost上运行良好,但是当我在godaddy共享主机上托管时,我返回了一个错误:Swift_TransportException 无法与主机smtp.gmail.com建立连接[拒绝连接#111]

我已经尝试了StackOverflow上几乎所有可用的解决方案。但是,它并没有解决问题。

MailController.php

class MailController extends Controller {
   public function send(Request $request){

        $this->validate($request, [
            'name'     =>  'required',
            'email'  =>  'required|email',
            'message' =>  'required'
        ]);

        $data = array(
            'name'      =>  $request->name,
            'message'   =>   $request->message
        );

        Mail::to('mail@gmail.com')->send(new SendMail($data));
        return back()->with('success', 'Thanks for contacting us!');
   }
}

config / mail.php

return [

    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'smtp.gmail.com'),

    'port' => env('MAIL_PORT', 587),

    'from' => ['address' => 'email@gmail.com', 'name' => 'Rohit Kumar'],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    'username' => env('MAIL_USERNAME'),

    'password' => env('MAIL_PASSWORD'),

    'sendmail' => '/usr/sbin/sendmail -bs',

    'pretend' => false,

    'stream' => [
       'ssl' => [
           'allow_self_signed' => true,
           'verify_peer' => false,
           'verify_peer_name' => false,
       ],
    ],
];

.env

MAIL_DRIVER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

MAIL_USERNAME=email@gmail.com

MAIL_PASSWORD=gmail_password

MAIL_ENCRYPTION=tls

0 个答案:

没有答案