简体   繁体   中英

how to send email in laravel 5 using gmail

I want to send mail using my laravel application but i got some problems it send error saying my smtp server can't be reached .

my mail configation

<?php

return [

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

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

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

    'from' => ['address' => 'myemail@gmail.com', 'name' => 'do not replay'],

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

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

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

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


];

my .env file

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:XewgRN8avAbSmWxu2IXcB5b3AhwSfdffm9VmpT/0A8k=
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=clear
DB_USERNAME=root
DB_PASSWORD=""

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=myapppaswword
MAIL_ENCRYPTION=tls 

but it generate this error

Swift_TransportException in AbstractSmtpTransport.php line 383:
Expected response code 220 but got code "421", with message "421 Cannot connect to SMTP server 74.125.206.108 (74.125.206.108:587), connect error 10060
"

I searched for solution but i could not find one any help will be appreciated

I believe you can find what you need in this linked post.

This problem can generally occur when you do not enable two step verification for the gmail account you are using to send an email. So first, enable two step verification, you can find plenty of resources for enabling two step verification. After you enable it, then you have to create an app password. And use the app password in your .env file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM