Level 33
check your .env file setting and make sure it should be correct
and you need to create your cache
php artisan config:cache
or
php artisan optimize:clear
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to make an API route to send a mail but I have this error : Connection could not be established with host :stream_socket_client().
mail.php
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => env('MAIL_AUTH_MODE'),
],
.env
MAIL_MAILER=smtp
[email protected]
MAIL_PORT=2525
MAIL_USERNAME=me
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME="${APP_NAME}"
controller
public function sendEmail()
{
$user = User::where('email', request()->input('email'))->first();
$token = Password::getRepository()->create($user);
$user->sendPasswordResetNotification($token);
}
route
Route::post('mail', [AuthentificationController::class, 'sendEmail']);
In postman I pass the mail adress in the body.
I don't know if I have to change some security settings somewhere.
check your .env file setting and make sure it should be correct
and you need to create your cache
php artisan config:cache
or
php artisan optimize:clear
Please or to participate in this conversation.