无法获得请求数据laravel 5.6

I want send email after input data from request to database, but i get message

Undefined variable: email

I dont know where code i fix. Help me somebody. Thanks very much

public function insert(Request $req){

$name = $req->input('name');
$email = $req->input('email');
$date = $req->input('date'); 
$kota = $req->input('kota');     
$line = $req->input('line');   

$cek = DB::table('peserta')->where('email',$email)->count();
  if ($cek > 0 and count($error) > 0 ) {
    $pesan = [];
    $pesan['halu'] = 'danger';
    $pesan['message'] = 'Email anda sudah terdaftar';
  }
  else{
    if($imageopini !=null){
      DB::table('peserta')->insert(['nama' => $name, 'email' => $email, 'ttl' => $date, 'kota' => $kota,
    'line' => $line]);

  $data = array('name'=>"Sam Jose", "body" => "Test mail");

    Mail::send('email',$data, function($message) {
        $message->to($email, $name )
                ->subject('Test');
        $message->from('super@gmail.com','Super Event');
    });
    }
    $pesan = [];
    $pesan['halu'] = 'success';
    $pesan['message'] = 'Data anda sukses disimpan, silahkan tunggu pengumuman pemenang.';
  }
  return view('formlomba',$pesan);
}

And here i attachment HTML code. I'm looking the tag html is corretly. Whats wrong with this?

<form class="contact100-form validate-form" action="/formlomba" method="post" enctype="multipart/form-data">

<div class="wrap-input100 validate-input" data-validate="Name is required">
                <input class="input100" type="text" name="name" placeholder="Nama">
                <span class="focus-input100-1"></span>
                <span class="focus-input100-2"></span>
            </div>

            <div class="wrap-input100 validate-input" data-validate = "Valid email is required: ex@abc.xyz">
                <input class="input100" type="email" name="email" placeholder="Email">
                <span class="focus-input100-1"></span>
                <span class="focus-input100-2"></span>
            </div>

            <div class="wrap-input100 validate-input" data-validate = "Valid email is required: ex@abc.xyz">
                <input class="input100" type="email" name="emailulang" placeholder="Ketik Ulang Email">
                <span class="focus-input100-1"></span>
                <span class="focus-input100-2"></span>
            </div>

....

    <div class="container-contact100-form-btn">
      <button class="contact100-form-btn" type="submit" id="btnselesai">
        Selesai
      </button>
    </div>

Mail::send('email',request()->all(), function($message) {
            $message->to(request()->input('email'), 'icad')
                    ->subject('Test');
            $message->from('s@gmail.com','Super Event');
        });

Try this:

Mail::send('email',$data, function($message) use ($email, $name) {
    $message->to($email, $name )
            ->subject('Test');
    $message->from('super@gmail.com','Super Event');
});

While using closure you have you pass your external variable with use keyword. Good Luck !!!

set your form action with route like this

action="{{ route('formlomba') }}"

Make sure your route define with Route::post


In all your <input> tags add required tag


To catch data, use

  1. $request->get('emal');
  2. Input::get('email') # import this as well use Illuminate\Support\Facades\Input;