Umut Savas
Umut Savas

Reputation: 113

Error sending email using Gmail SMTP with Laravel

I'm trying to send mails from my webserver using Laravel 6 like this:

Mail::send('feedback', ['email' => $email, 'text' => $text], function($message) use ($receiver)
{
    $message->to($receiver, 'The receiver')->subject('New Feedback');
});

I added my login information into my .env file according to this page from google:

https://support.google.com/mail/answer/7126229?hl=de

my .env file:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=my_gmail_login_password
MAIL_ENCRYPTION=tls

but I keep getting this error message:

Expected response code 250 but got code "530", with message "530-5.7.0 Authentication Required. Learn more at
530 5.7.0  https://support.google.com/mail/?p=WantAuthError

It looks like I would have used wrong credentials but I'm able to login with these credentials in gmail.

I also enabled insecure apps in my gmail settings.

I also tried to solve it by creating an app password and using it instead of my gmail password.

Nothing worked.

Does someone have an idea what I'm doing wrong?

Upvotes: 0

Views: 2603

Answers (2)

Umut Savas
Umut Savas

Reputation: 113

I could solve it by changing

MAIL_DRIVER=smtp

to

MAIL_DRIVER=sendmail

now I don't get any errors logged and everything seems to be working fine, but the mails don't get delivered to the mail address where they should be.

Upvotes: 1

M.Idrish
M.Idrish

Reputation: 437

when you want to send email from gmail you have to change some settings in gmail account.

Step 1: Configure your Google Account Login to your Google Email Account and click on Google Account Button. This button is display when you click on the profile picture in your Gmail Dashboard as shown

Once you are on My Account Page then click on Security and scroll down to the bottom and you will find ‘Less secure app access’ settings. Click on the radio button to set it ON.

I think this link is helpful to you https://medium.com/@agavitalis/how-to-send-an-email-in-laravel-using-gmail-smtp-server-53d962f01a0c

Upvotes: 1

Related Questions