在laravel中的Swift_TransportException错误
在laravel中的Swift_TransportException错误
我正在尝试创建一个联系表单,将消息发送到我的电子邮件地址。当我测试时,出现了以下错误:
Swift_TransportException
预计的响应代码为250,但得到的代码为"530",消息为"530 5.7.0 必须先发出STARTTLS命令。bv17sm3597476wib.13 - gsmtp"
这是我的控制器代码:
public function contact() { $data = array( 'name' => Input::get('name') ); Mail::send('emails.contact', $data, function($message){ $message->to('test@gmail.com', 'Nikki')->subject('登录详细信息'); }); }
这是我的contact.blade.php代码:
{{ Form::open(array('id' => 'contact-frm', 'class' => 'contact-form', 'route' => 'contact')) }} {{ Form::label('fname', '姓名') }} {{ Form::text('fname') }} {{ Form::label('surname', '姓氏') }} {{ Form::text('surname') }} {{ Form::label('email', '电子邮件') }} {{ Form::text('email') }} {{ Form::label('message', '消息') }} {{ Form::textarea('message') }} {{ Form::submit('提交') }} {{ Form::close()}}
mail.php文件内容:
'driver' => 'smtp', 'host' => 'smtp.gmail.com', 'port' => 587, 'from' => array('address' => 'myEmail@gmail.com', 'name' => "Nikki"), 'encryption' => 'tls', 'username' => 'myEmail@gmail.com', 'password' => 'MyPassword', 'sendmail' => '/usr/sbin/sendmail -bs', 'pretend' => false,
当你修改了.env文件后,你需要重启服务器。
Sometimes you may encounter the error "Swift_TransportException error" in Laravel when making changes to the .env file. This error occurs because Laravel caches the configuration files, including the .env file, for better performance. Therefore, when you make changes to the .env file, you need to restart your server for the changes to take effect.
To resolve this error, simply restart your server. This can be done by stopping and starting the server or using the appropriate command for your server environment. Once the server is restarted, Laravel will re-cache the configuration files and the changes made in the .env file will be applied.
It is important to note that restarting the server is necessary only when you make changes to the .env file. For other changes in your Laravel application, such as code modifications or migrations, you do not need to restart the server.