Support the ongoing development of Laravel.io →
posted 9 years ago
Mail

Hello,

I am very new to Laravel and thats why I have started with Laravel 4.2. Currently I am working on a Contact Page where user will submit the from and the website owner/admin should get the mail containing all the information. I have used jQuery Validation instead of Laravel validation. The problem I am facing is after clicking on "Send Mail" button the validations are coming properly but unable to send the mail. The page remains in the same stage only.

Following is the code for Controller:

public function postContact()
  {
    //Get all the data and store it inside Store Variable
    $data = Input::all();
    //$formdata = new formdata($data);
    //$temp = $formdata->save();
    if ($data)
    {
        //Send email using Laravel send function
      Mail::send('emails.contact', $data, function($message) use ($data)
      {
            //email 'From' field: Get users email add and name
        $message->from($data['email'] , $data['name']);
            //email 'To' field: change this to emails that you want to be notified.                    
        $message->to('example@mail.com', 'Example')->subject('contact request');

      });

      return View::make('contact')->with('success', 'You have registered successfully');  
    }
    else
    {
      return View::make('contact')->with('fail', 'An error occurred!');
    }
  }

Please any kind of help will be very helpful to me.

Thanks in advance.

Last updated 2 years ago.
0

If you remove the jquery validation does it work?

nb You should use server side (laravel) validation even if using client side (jquery) validation

0

Please try the below code..


public function postContact()
  {
            $from = Input::get('email');
            $name = Input::get('name');

    if ($from)
    {
      Mail::send('emails.contact', $data, function($message) use ($from, $name)
      {
            
            $message->from('yourmail@example.com' , 'Your Name')->to($from)->subject('Contact Request');

      });
        
    }
      return View::make('contact')->with('success', 'You have registered successfully');

    else
    {
      return View::make('contact')->with('fail', 'An error occurred!');
    }
  }

Last updated 9 years ago.
0

elite123 said:

If you remove the jquery validation does it work?

nb You should use server side (laravel) validation even if using client side (jquery) validation

Without the jQuery validation it works, I know it better to use server side validation but how to use jquery validation?

0

Your problem is with your jquery code then - can you post that (or you might get more responses in a jquery forum)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.