Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

redroseamit's avatar

mail sending error using gmail smtp using laravel

while using port 465 then getting this error

Expected response code 220 but got an empty response 	

while using 587

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 i25sm4486677pgb.33 - gsmtp 

but when i was using mailtrap it was working fine.

0 likes
31 replies
sr57's avatar

Have you succeed sending email with another smtp?

sr57's avatar

Not my question, other smtp than gmail in Laravel?

redroseamit's avatar

sorry sir i am not getting you ...smtp there are lot of smtp ...mailtrap.io was working fine previously.

hanif-king's avatar

are you saying that you want to send an email from an application to a specific google mail account ?

sr57's avatar

You don't need gmail smtp for that, you can use which you want.

Sorry for mailtrap I don't understant you use it from Laravel. Does the setup in Laravel is the same between mailtrap and gmail smtp?

redroseamit's avatar

no it is diffrent ... here is the env file

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=<<<<XXXXXXXXXXXXXxx>>>>
MAIL_PASSWORD=<<<<gmail app code >>>>>
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null

and this is mail

    'default' => env('MAIL_MAILER', 'smtp'),

'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.gmail.com'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('XXXXXXXXXXXXX'),
            'password' => env('XXXXXXXXXXX'),
            'timeout' => null,
            'auth_mode' => null,
        ],


newbie360's avatar

btw, gmail smtp has outgoing limit

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=your-email-password
MAIL_ENCRYPTION=tls
redroseamit's avatar

here is the env file

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=<<<<XXXXXXXXXXXXXxx>>>>
MAIL_PASSWORD=<<<<gmail app code >>>>>
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=null

and this is mail

    'default' => env('MAIL_MAILER', 'smtp'),

'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.gmail.com'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('XXXXXXXXXXXXX'),
            'password' => env('XXXXXXXXXXX'),
            'timeout' => null,
            'auth_mode' => null,
        ],


hanif-king's avatar

if you are sending your email from localhost not a server online then you need to configure you email account for Enabling less secure apps to access Gmail and if its in online server google mostly accepts ssl encryption for that you need to configure your .env file with this info . MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=465 [email protected] MAIL_PASSWORD=yourEmailPassword MAIL_ENCRYPTION=SMTP

1 like
redroseamit's avatar

sir i already did.....but still getting above error i tried both and less secure app is enable in gmail account.

sr57's avatar
'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.gmail.com'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],

If pb; try to remove the 2 last lines timeout & auth

sr57's avatar

sure?, you wrote XXXXX .... (no need to hide a parameter)

redroseamit's avatar

sorry sir ts not parameter it was my gmail account so i type XXXXX

sr57's avatar

:-)

so begin by simplifying your code, see my last post, don't use your .env file.

hanif-king's avatar

please attach your email sending code and your configuration for email in .env

redroseamit's avatar

i did it already ..then only given two above errors.

newbie360's avatar

if i'm correct, you need enable IMAP in your gmail account ?

redroseamit's avatar

sir it was correct i also forgot to enable that one..now i enabled it...but still the error is same

sr57's avatar
'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => 'smtp.gmail.com',
            'port' => 587,
            'encryption' => 'tls',
            'username' => '<you>@gmail.com',
            'password' => 'your pwd',
        ],

your_pwd is the one you connect to your @gmail.com

try also with port 465

sr57's avatar

Look at your account, gmail maybe has send you a validation link.

redroseamit's avatar

sir i am getting error only...Expected response code 220 but got an empty response

newbie360's avatar
Level 24

just make this more clear.... don't change any settings in mail.php, the default setting is

    'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME'),
            'password' => env('MAIL_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],

change .env

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

make sure enabled IMAP under POP/IMAP settings in your gmail account, try send email

1 like
redroseamit's avatar

thanks sir now its working ... that was correct i don't need to do anything in mail.php..... instead of password its gmail is creating a app password ....now its worked.



1 like
newbie360's avatar

now for the security reason, you shouldn't upload .env to anywhere eg, github

and the .env shouldn't readable by http://your-project/.env

if the project is only you to dev, you may change like this

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
#MAIL_USERNAME=
#MAIL_PASSWORD=
MAIL_ENCRYPTION=tls

mail.php

    'mailers' => [
        'smtp' => [
            'transport' => 'smtp',
            'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
            'port' => env('MAIL_PORT', 587),
            'encryption' => env('MAIL_ENCRYPTION', 'tls'),
            'username' => env('MAIL_USERNAME', '[email protected]'),
            'password' => env('MAIL_PASSWORD', 'your-gmail-password'),
            'timeout' => null,
            'auth_mode' => null,
        ],
1 like
redroseamit's avatar

thanks sir i know that ...i already hide env file using htacess.

JanTay's avatar

Hi, I've just set up email on my laravel app and followed this https://blog.quickadminpanel.com/add-two-factor-email-verification-to-laravel-auth/

In my .env I have the following:

MAIL_MAILER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=465 MAIL_USERNAME= This is the email address of the gmail account MAIL_PASSWORD=This is the 16 digit code that is produced MAIL_ENCRYPTION=ssl MAIL_FROM_ADDRESS= I just repeated my email address here MAIL_FROM_NAME="${APP_NAME}"

Hope this helps.

Please or to participate in this conversation.