1

So I am trying to send password reset email and this is my routes for it:

Route::get('/password/remind', function () {
    return view('auth.password-remind');
})->name('password.remind');
Route::post('/password/remind', [RemindController::class, 'store'])->name('password.send');

Route::get('/password/reset/{token}', function () {
    return view('auth.password-reset');
})->name('password.reset');

And inside RemindController I have:

$data = $this->validate($request, [
            'email' => ['required', 'exists:users,email'],
            '_token' => '',
        ]);

        Mail::send('emails.password-reset', [
            'token' => $data['_token']
        ], function ($message) use ($data) {
            $message->subject('Reset Password Request');
            $message->to($data['email']);
        });

And then this is the email it should send:

Reset password <a href="{{ route('password.reset', $token) }}">here</a>

This is my form for sending email:

<form action="{{ route('password.send') }}" method="post" class="remind-form">
                <input name="_token" type="hidden" value="{{ csrf_token() }}"/>
                <div class="form-group" error="email">
                    <input class="form-control" name="email" type="email" />
                </div>

                <div class="form-footer">
                    <button type="submit" class="auth-btn">Send</button>
                </div>
            </form>

But when I submit I get errors:

Connection could not be established with host mailhog :stream_socket_client(): php_network_getaddresses: getaddrinfo failed: No such host is known.

my .env

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=465
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=myemail@gmail.com
zyyyzzz
  • 220
  • 2
  • 11
  • Does this answer your question? [Connection could not be established with host mailhog :stream\_socket\_client()](https://stackoverflow.com/questions/67633041/connection-could-not-be-established-with-host-mailhog-stream-socket-client) – Wahyu Kristianto Aug 31 '21 at 17:24
  • is mailhog running? are you using laravel sail? or brew mailhog? What is your local setup? – Cameron Sep 01 '21 at 00:33

3 Answers3

0

hello try ssl instead tls

MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=465
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl
MAIL_FROM_ADDRESS=myemail@gmail.com
Hafsa
  • 29
  • 6
0

Firstly, have you set up mailhog in your device?

Set the host value should be MAIL_HOST=mailhog and MAIL_ENCRYPTION=null

Then, clear your config cache after changing your .env file values.

php artisan config:clear
php artisan cache:clear

You can try mailtrap which is user-friendly

Create a mailtrap account and add these credentials and details in your .env

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME= (your username from mailtrap)
MAIL_PASSWORD= (your password from mailtrap)
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS= myemail@gmail.com
-1

Clear cache using artisan command

php artisan cache:clear


php artisan config:clear

Restart your server

sudo service apache2 restart
VIKAS KATARIYA
  • 5,867
  • 3
  • 17
  • 34