在laravel中的Swift_TransportException错误

5 浏览
0 Comments

在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,

0
0 Comments

在Laravel中出现了Swift_TransportException error的问题。这个问题的出现原因是邮件驱动配置错误。为了解决这个问题,我们需要在.env文件中修改邮件驱动为sendmail。

具体的解决方法如下:

1. 打开.env文件。

2. 找到MAIL_DRIVER这一行的配置。

3. 将其值改为sendmail。

4. 保存文件。

修改后的配置如下所示:

MAIL_DRIVER=sendmail

通过以上的修改,我们可以解决Swift_TransportException error in Laravel中的问题。这样,我们就可以正常发送邮件了。

0
0 Comments

当你修改了.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.

0
0 Comments

在Laravel 5中,出现(Swift_TransportException error in laravel)这个问题是因为.env文件的问题。Laravel默认在config/mail.php中设置了一个加密值,而.env文件中的值会覆盖这个默认设置。因此,只需要将.env文件中的MAIL_ENCRYPTION=null改为MAIL_ENCRYPTION=tls即可解决这个问题。

0