从输入请求数据到数据库后,我想发送电子邮件,但收到消息
未定义变量:电子邮件
我不知道我在哪里修复代码。帮帮我非常感谢
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);
}
在这里我附上了HTML代码。我在看标签html是正确的。怎么了?
<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>
答案 0 :(得分:0)
Mail::send('email',request()->all(), function($message) {
$message->to(request()->input('email'), 'icad')
->subject('Test');
$message->from('s@gmail.com','Super Event');
});
答案 1 :(得分:0)
尝试一下:
Mail::send('email',$data, function($message) use ($email, $name) {
$message->to($email, $name )
->subject('Test');
$message->from('super@gmail.com','Super Event');
});
在使用闭包时,您要使用 use 关键字传递外部变量。 祝好运 !!!
答案 2 :(得分:0)
使用这样的路线设置表单操作
action="{{ route('formlomba') }}"
确保您的路线使用
定义Route::post
在您所有的<input>
标签中添加required
标签
要捕获数据,请使用
$request->get('emal');
Input::get('email')
#也将其导入use Illuminate\Support\Facades\Input;