Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Flex's avatar
Level 4

Live server did not work for contact us form well in Laravel

my local laravel project is working well. but after hosting project with live server it is working all except contact us form. this is my contact form

<div class="content">
@include('partials.alerts')
    <h1 class="heading">Contact Us</h1>
    
    
    <form method="post" action="{{url('form')}}#contact">
            {{csrf_field()}}
            <div class="form">
  <div class="input-flex">
    <input type="text" name="name" placeholder="Name*" /><br><br>
    <span style="color:red">@error('name'){{$message}}@enderror</span>
    <input type="email" name="email" placeholder="E-mail*" /><br><br>
    <span style="color:red">@error('email'){{$message}}@enderror</span>
    <input type="tel" class="full-width" name="telephone" placeholder="Phone number*" /><br><br>
    <span style="color:red">@error('telephone'){{$message}}@enderror</span>
    <textarea cols="2" rows="2" class="full-width" name="message" placeholder="Message"></textarea>
    </div>
  <button  class="conbtn" type="submit">Submit</button>

and my scrolling navigation for contact is

<nav class="navbar">
   <a href="#contact">contact</a>
</nav>

and controller for contact us is

protected function store(Request $request)
    {
        //validate request
        $this->validate($request,[
            'name' => 'required|max:100',
            'email' => 'required|email',
            'telephone' => 'required',
        ]);

        $user = new User;

        $user->name = $request->input('name');
        $user->email = $request->input('email');
        $user->telephone = $request->input('telephone');
        $user->message = $request->input('message');
        
        $user->save();

        $verifyUser = VerifyUser::create([
            'user_id' => $user->id,
            'token' => Str::random(40)
        ]);

        Mail::to($user->email)->send(new VerifyMail($user));

      return redirect('/#contact')->with('info', 'We sent you an activation code. Check your email and click on the link to verify');
    }

my contact us verification message and for validation messages redirect to contact section after submitting submit button. this system working well in my local machine. but in live server got following error messageSorry, this page doesn't exist. Please check the URL or go back a page. 404 Error. Page Not Found.

and I can monitor there are different urls in my local and live server after submitting contact form localhost is like http://localhost:8000/#contact but live server is like https://academi.com/form#contact

I am confused with this. how could I fix this problem

0 likes
9 replies
vincent15000's avatar

You would try to change this redirect('/#contact') to redirect('#contact').

Snapey's avatar

what are your routes in web.php for GET of page with contact form, and the POST route for contact?

1 like
Flex's avatar
Level 4

@Snapey my web.php file is like this

Route::get('/', function () {
    return view('welcome');
});

Route::post('form','App\Http\Controllers\UserController@store');

Route::get('/user/verify/{token}', 'App\Http\Controllers\UserController@verifyUser');

navigation manage with javascript scrolling

<nav class="navbar">
    <div id="nav-close" class="fas fa-times"></div>
    <a href="#home">home</a>
    <a href="#idea">Idea</a>
    <a href="#about">about</a>
    <!-- <a href="#shop">shop</a> -->
    <a href="#packages">packages</a>
    <a href="#reviews">reviews</a>
    <a href="#contact">contact</a>
    <a href="#video">video</a>
</nav>
1 like
Snapey's avatar

could you be getting a validation error on live?

what happens locally if you deliberately make a validation error?

1 like
Flex's avatar
Level 4

@Snapey it is working fine in locally. problem with live server? No validation error on live. it is occured 404 error

1 like
Snapey's avatar

@Flex so locally if you do a validation error it redirects to /#contact?

1 like
Flex's avatar
Level 4

I think problem is with my live server db not connect with my project. then how could I check this problem connected with the project db?

1 like
devutoo's avatar

If you suspect the DB connection, I guess, you'll check your DB settings in your live .env file. And you could check your live log file for error messages.

1 like

Please or to participate in this conversation.