tisuchi's avatar

Sending email problem with gmail

I am trying to send email from localhost with gmail. I already Allow less secure apps: ON and I edited my mail.php file like as follows-

return [

    'driver' => env('MAIL_DRIVER', 'smtp'),

    'host' => env('MAIL_HOST', 'smtp.gmail.com'),

    'port' => env('MAIL_PORT', 587),

    'from' => ['address' => 'callforconference@gmail.com', 'name' => 'call for conference'],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

     'username' => env('callforconference'),

    'password' => env('*****************'),

    'sendmail' => '/usr/sbin/sendmail -bs',

];

And .env, I edited like that-

MAIL_DRIVER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

MAIL_USERNAME=callforconference

MAIL_PASSWORD=**************

MAIL_ENCRYPTION=tls

Now within controller, I wrote the following code-

$user = User::find(1)->toArray();
        
        Mail::send('emails.joinMail', $user, function($message) use ($user){

            $message->to($user['email']);
            $message->subject('Welcome to cFc Network');
        });

However, at the end of the day, I got following error-

Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 250 but got code "530", with message "530-5.5.1 Authentication Required. Learn more at
530 5.5.1 https://support.google.com/mail/answer/14257 22sm44931266pfh.48 - gsmtp
"

Any opinion to solve that?

0 likes
17 replies
jimmck's avatar

I think help may start with the link in the error message?

tisuchi's avatar

I believe, I tried with all the instructions that they mentioned... but still same...

1 like
jimmck's avatar

Did you respond to the gmail email regarding use of your account?

jimmck's avatar

From this website click on the link Google so helpfully provided you in the error message. Or check your email.

mehany's avatar

@tisuchi this happens to me to! Even though if I put the correct name rather than 'call for conference' and match the info exactly as my account info. I am thinking Gmail is blocking that as it is a free service, and some times it work, other times it does not. I am thinking since they have business plans, gmail wants you to subscribe to one.

P.S many of my domains are registered with Godaddy so I use their SMTP servers

anon34372's avatar

This is mine .env:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=something@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls

mail.php

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.gmail.com'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => 'something@gmail.com', 'name' => 'jesse'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    //Maybe here is your problem
    'username' => env('MAIL_USERNAME','something@gmail.com'),
    'password' => env('MAIL_PASSWORD', 'password'),
    'sendmail' => '/usr/sbin/sendmail -bs',
];

gmail : two step verification OFF and less-secure-apps ON

And try this:

php artisan config:cache

service nginx restart

tisuchi's avatar

well... @mehany

In this case, what would be the best email service for laravel, free or paid version?

1 like
mehany's avatar

many people use mailgun. You have up to 10000 emails per month for free

tisuchi's avatar

Thank you @JesseVeritas

I followed the same steps however, not working with me. I dont know why...

1 like
anon34372's avatar

Can you show us your current state of .env and mail.php?

tisuchi's avatar

@JesseVeritas

In .env file

MAIL_DRIVER=smtp

MAIL_HOST=smtp.gmail.com

MAIL_PORT=587

MAIL_USERNAME=callforconference@gmail.com

MAIL_PASSWORD=**************

MAIL_ENCRYPTION=tls

and within mail.php file,

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.gmail.com'),
    'port' => env('MAIL_PORT', 587),
    'from' => ['address' => 'callforconference@gmail.com', 'name' => 'callforconference'],
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),

    //Maybe here is your problem
    'username' => env('MAIL_USERNAME', 'callforconference@gmail.com'),
    'password' => env('MAIL_PASSWORD',  '************'),
    'sendmail' => '/usr/sbin/sendmail -bs',
];

dezgo's avatar

Try this when sending the email

$user = User::find(1)->toArray();
        
        Mail::send('emails.joinMail', ['user' => $user], function($message) use ($user){
        $message->from('callforconference@gmail.com', 'callforconference')
                ->to($user['email'])
                ->subject('Welcome to cFc Network');
        });

Basically I've just added the from in case it was required, and I thought that user variable had to be passed in as an array...

Please or to participate in this conversation.