Reputation: 27
I'm trying to send emails through Laravel and Gmail usage, nevertheless, it throws this error:
Connection could not be established with host "mailpit:1025": stream_socket_client(): php_network_getaddresses: getaddrinfo for mailpit failed: No such host is known.
I don't understand why it tries to connect to Mailpit instead of Gmail.
My .env file looks like this:
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=[google app password]
MAIL_ENCRYPTION=ssl
and my routing looks like this:
Route::get('/senMail', function () {
try {
Mail::to('[email protected]’')->send(new Subscribe());
} catch (Throwable $e) {
return '<div>FAILED ' . $e . '</div>';
}
});
the subscribe template is a regular php artisan make:mail Subscribe --markdown=emails.subscribers
I tried to run php artisan cache:clear
and php artisan config:clear
but error kept being thrown, I also changed port 587 to 465 with no success.
Also tried this config in config/mail.php
file:
'stream' => [
'ssl' => [
'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false,
],
],
Upvotes: 2
Views: 27162
Reputation: 29
In my case the error was resolved by simply running the following command:
php artisan config:cache
Upvotes: 1
Reputation: 1
I run this grep -R mailpit * | egrep -v storage
by Juan Pablo Arango Lizcano
and discovered that cache is using the unconfigured .env
and then I run
php artisan config:clear
to remove the cached configuration
Upvotes: -1
Reputation: 27
by @aynber: "Try grep -R mailpit * | egrep -v storage from your project root to find out where it's been referenced."
Its been a little long time since i had thsi issue, but this helped me find the line of code that was still using other smtp provider. Just replaced it with mine.
Upvotes: -1
Reputation: 11
Try this both commands in terminal
php artisan route:clear // this clear the route cache
php artisan config:cache // this clear the config cache
Upvotes: -5