Search code examples
phplaravelhttp-redirectenvironment-variablesmessage

Redirection after sending mail not working | Laravel


What I want:

I want to display a message when the user is redirected back to the form page after a mail is sent.

What I am doing

Here is the code in my SendEmailController.php:

return back()->with('success', 'Mail Sent !');

Here is my code in my view/index.blade.php:

@if ($message = Session::get('success'))
    <div class="alert alert-success alert-block">
        <button type="button" class="close" data-dismiss="alert">×</button>
            <strong>{{ $message }}</strong>
    </div>
@endif

I want to mention that I just followed this tutorial: https://www.webslesson.info/2018/09/simple-way-to-sending-an-email-in-laravel.html

In practice :

Nothing is displayed, the main page remain the same and my mail is sent.

What i tried :

I tried setting a route as following:

In my web.php:

Route::get('/succeed', 'PagesController@succeed')

In my PagesController.php:

return view('index')->with('success', 'Mail Sent !');

When I go to http://localhost/succeed, my div is displayed.

In the end, I don't understand why I don't understand why that div don't want to show up.

Edit:

Tried:

redirect()->back()->with('success', 'Mail Sent !');

Not fixing the issue


Solution

  • My problem is fixed, I had some AJAX in the background that was blocking the redirection.

    Thanks you a lot for giving me answers.