我正在尝试使用laravel邮件制作联系表。它在localhost上运行良好,但是当我在godaddy共享主机上托管时,我返回了一个错误:Swift_TransportException 无法与主机smtp.gmail.com建立连接[拒绝连接#111]
我已经尝试了StackOverflow上几乎所有可用的解决方案。但是,它并没有解决问题。
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!');
}
}
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,
],
],
];
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=email@gmail.com
MAIL_PASSWORD=gmail_password
MAIL_ENCRYPTION=tls