user3656554
user3656554

Reputation: 111

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,

Upvotes: 7

Views: 40491

Answers (6)

MH Fuad
MH Fuad

Reputation: 775

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

MAIL_DRIVER=sendmail

every time after change .env file clear config

php artisan config:clear

Upvotes: 2

Sachin Vairagi
Sachin Vairagi

Reputation: 5344

In my case, I was migrating project to the new server (Ubuntu 20.04), so I have to install

sendmail

by following command -

sudo apt-get install sendmail

Upvotes: 0

José
José

Reputation: 1

When changing the .env you need to restart your server or in linux terminal runs

php artisan config:cache  

Upvotes: 0

Ahamed Rasheed
Ahamed Rasheed

Reputation: 779

Check your .env file.

I was using mailgun

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=1230
[email protected]
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=tls

[email protected]
MAILGUN_SECRET=null

I had the same problem, My fault was MAIL_ENCRYPTION was given a wrong input.

Upvotes: 0

androsfat
androsfat

Reputation: 741

When changing the .env you need to restart your server

Upvotes: 3

PapaHotelPapa
PapaHotelPapa

Reputation: 697

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.

Upvotes: 4

Related Questions