我在客户站点上有一个“联系人”和“预订”表格。 “联系”表单运行良好,填写后将其发送到我的mailtrap.io帐户。据我所知,“预订”表单和控制器的结构与“联系表单”的结构完全相同,但是,填写“预订”表单时不会发送电子邮件。我不知道为什么。
当我在“联系人”和“预订”表单上添加数据时,我可以看到数组结果。但是,如上所述,用于“预订”表格的电子邮件并未发送到mailtrap.io。
这是我的web.php文件
Route::get('reservation', 'PageController@reservation');
Route::post('reservation', 'PageController@postReservation');
Route::get('contact', 'PageController@contact');
Route::post('contact', 'PageController@postContact');
这是我的“联系人”和“预订”表格的管理员。联系人和预订功能在同一控制器中:
public function reservation()
{
return view('reservation');
}
public function postReservation(Request $request)
{
dd($request->all()); //-> Fill in data to test if form works
$request->validate([
'name' => 'required|string|min:2',
'email' => 'required|email',
'phone' => 'required|digits:10',
'date' => 'required|date_format:Y/m/d|after:today',
'seats' => 'required|integer',
'message' => 'min:10'
]);
$data = array (
'name' => $request->name,
'email' => $request->email,
'phone' => $request->phone,
'date' => $request->date,
'time' => $request->time,
'seats' => $request->seats,
'reservationMessage' => $request->message,
);
Mail::send('emails.reservation', $data, function ($message) use ($data) {
$message->from('contact@venueat50.co.za');
$message->to('info@webdevpro.co.za');
$message->subject($data['name']);
});
return redirect('reservation')->with('success', 'Thank you. We will contact you to confirm the booking');
}
public function contact()
{
return view ('contact');
}
public function postContact(Request $request)
{
dd($request->all()); //-> Fill in data to test if form works
$request->validate([
'name' => 'required|string|min:2',
'email' => 'required|email',
'number' => 'required|digits:10',
'subject' => 'required|min:3',
'message' => 'required|min:10'
]);
$data = array(
'name' => $request->name,
'email' => $request->email,
'number' => $request->number,
'subject' => $request->subject,
'bodyMessage' => $request->message
);
Mail::send('emails.contact', $data, function($message) use ($data) {
$message->from('contact@venueat50.co.za');
$message->to('info@webdevpro.co.za');
$message->subject($data['subject']);
});
return redirect('contact')->with('success', 'Your message has been sent. We will reply promptly');
}
我还为“联系人”和“预订”表格设置了电子邮件模板。不知道是否需要。
让我还附上“联系方式”和预订表格:
联系表格:
<form method="post" id="contact-form" action='{{ action('PageController@postContact') }}'>
{{ csrf_field() }}
@if (session('success'))
<div class="alert alert-success">
{{ session('success') }}
</div>
@endif
<label>Name</label>
@if($errors->has('name'))
<small class="form-text invalid-feedback">{{ $errors->first('name') }}</small>
@endif
<p><input type="text" name="name" class="reservation-fields" value="{{ old('name') }}"/></p>
<label>Email</label>
@if($errors->has('email'))
<small class="form-text invalid-feedback">{{ $errors->first('email') }}</small>
@endif
<p><input type="text" name="email" class="reservation-fields" value="{{ old('email') }}"/></p>
<label>Mobile Nr</label>
@if($errors->has('number'))
<small class="form-text invalid-feedback">{{ $errors->first('number') }}</small>
@endif
<p><input type="text" name="number" class="reservation-fields" value="{{ old('number') }}"/></p>
<label>Subject</label>
@if($errors->has('subject'))
<small class="form-text invalid-feedback">{{ $errors->first('subject') }}</small>
@endif
<p><input type="text" name="subject" class="reservation-fields" value="{{ old('subject') }}"/></p>
<label>Message</label>
@if($errors->has('message'))
<small class="form-text invalid-feedback">{{ $errors->first('message') }}</small>
@endif
<p> <textarea name="message" id="msg-contact" class="reservation-fields" rows="7"></textarea></p>
<p class="antispam">Leave this empty: <input type="text" name="url" /></p>
<p class="contact-btn"><input type="submit" value="Send message" id="submit"/></p>
最后是预订表格:
<form method="post" id="reservation-form" action={{ action('PageController@postReservation') }}>
{{ @csrf_field() }}
<div class="row">
<div class="col-md-4">
<label>Name*</label>
<p><input type="text" name="name" class="reservation-fields" required/></p>
</div>
<div class="col-md-4">
<label>Email*</label>
<p><input type="text" name="email" class="reservation-fields" required/></p>
</div>
<div class="col-md-4">
<label>Phone*</label>
<p><input type="text" name="phone" class="reservation-fields" required/></p>
</div>
</div>
<!--end row-->
<div class="row">
<div class="col-md-4">
<label>Date*</label>
<p><input type="date" name="datepicker" id="datepicker" class="reservation-fields" size="30" required/></p>
</div>
<div class="col-md-4">
<label>Time*</label>
<p>
<select name="time" class="reservation-fields" >
<option value="10:00">10:00</option>
<option value="11:00">11:00</option>
<option value="12:00">12:00</option>
<option value="13:00">13:00</option>
<option value="14:00">14:00</option>
<option value="15:00">15:00</option>
<option value="16:00">16:00</option>
</select>
</p>
</div>
<div class="col-md-4">
<label>Seats*</label>
<p><input type="text" name="seats" class="reservation-fields" required/></p>
</div>
</div>
<!--end row-->
<label>Special Requests</label>
<p> <textarea name="message" id="message2" class="reservation-fields" cols="100" rows="4" tabindex="4"></textarea></p>
<p class="antispam">Leave this empty: <input type="text" name="url" /></p>
<p class="alignc"><input type="submit" value="Book Now" id="submit" /></p>