Skip to content
Advertisement

How to configure `.env` file in Laravel for sending mail?

Getting error while sending mail from a in Laravel website.

local.ERROR: Connection could not be established with host smtp.gmail.com [A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. #10060]

.env file

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=arafat@lasermedicalbd.com
MAIL_PASSWORD=app_specific_password
MAIL_ENCRYPTION=tls

Already googling but can’t get the solution yet. Whatever I change( PORT, DRIVER ) in .env file always shows the same error.

How to solve it !!

Advertisement

Answer

clear the env file cache

php artisan config:cache
php artisan cache:clear

configure mail.php

<?php

return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
    'port' => env('MAIL_PORT', 587),
    'from' => [
        'address' => 'yourEmail@gmail.com', 
        'name' => 'Your Title'
    ],
    'encryption' => 'tls',
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,
    'markdown' => [
        'theme' => 'default',
        'paths' => [
            resource_path('views/vendor/mail'),
        ],
    ],
];
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement