Most of the developers face situation where they wont be able to send email from localhost in Laravel using gmail credentials.

It is bit connected settings between Laravel and Gmail.

Steps to follow while setting it up in local

  1. Create gmail account so that you can use it for your Laravel application. eg: I have created account [email protected] with password [email protected]
  2. Go to gmail security settings to allow less secure app. By default, google has security not to allow other than gmail to send an email. You can check it here. Less secure app settings in gmail
  3. Add the following lines in your application .env

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

  5. After completing above steps. You may find following error. It is because of SSL check done by Laravel configuration.

  6. stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:\n error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

  7. You have to add following below code in your application /config/mail.php file.

  8. 'stream' => [
    'ssl' => [
    'allow_self_signed' => true,
    'verify_peer' => false,
    'verify_peer_name' => false,
    ],
    ],

  9. Now, clean and config the cache using commands.

  10. php artisan cache:clear
    php artisan config:cache

Congratulations, you are good to send emails from localhost in laravel using gmail creadentials.