Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift_TransportException error in laravel

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('[email protected]', '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' => '[email protected]', 'name' => "Nikki"),
'encryption' => 'tls',
'username' => '[email protected]',
'password' => 'MyPassword',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
like image 268
user3656554 Avatar asked Oct 09 '14 11:10

user3656554


3 Answers

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.

like image 99
PapaHotelPapa Avatar answered Oct 22 '22 14:10

PapaHotelPapa


When changing the .env you need to restart your server

like image 34
androsfat Avatar answered Oct 22 '22 14:10

androsfat


change your mail driver in .env file "smtp to sendmail" it works in my case.

MAIL_DRIVER=sendmail
like image 40
MH Fuad Avatar answered Oct 22 '22 15:10

MH Fuad