问题
I'm trying to create a contact form that email the message to my email address. When I tested it out I got this error
Swift_TransportException
Expected response code 250 but got code "530", with message "530 5.7.0 Must issue a STARTTLS command first. bv17sm3597476wib.13 - gsmtp "
This is my controller
public function contact()
{
$data = array(
'name' => Input::get('name')
);
Mail::send('emails.contact', $data, function($message){
$message->to('test@gmail.com', 'Nikki')->subject('Login Details');
});
}
and this is my contact.blade.php
{{ Form::open(array('id' => 'contact-frm', 'class' => 'contact-form', 'route' => 'contact')) }}
{{ Form::label('fname', 'Name') }}
{{ Form::text('fname') }}
{{ Form::label('surname', 'Surname') }}
{{ Form::text('surname') }}
{{ Form::label('email', 'Email') }}
{{ Form::text('email') }}
{{ Form::label('message', 'Message') }}
{{ Form::textarea('message') }}
{{ Form::submit('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,
回答1:
In Laravel 5, the problem comes from the .env
file. Laravel ships with a value set for encryption there that overrides your default setting in config/mail.php
. In .env
, change MAIL_ENCRYPTION=null
to MAIL_ENCRYPTION=tls
and you're good to go.
回答2:
When changing the .env
you need to restart your server
回答3:
Check your .env
file.
I was using mailgun
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=1230
MAIL_USERNAME=user@domain.com
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls
MAILGUN_DOMAIN=user@domain.com
MAILGUN_SECRET=null
I had the same problem, My fault was MAIL_ENCRYPTION
was given a wrong input.
回答4:
When changing the .env
you need to restart your server or in linux terminal runs
php artisan config:cache
来源:https://stackoverflow.com/questions/26277103/swift-transportexception-error-in-laravel