我有一个联系我们表单的控制器功能,它应该与控制器功能一起发送电子邮件,然后在表单提交时启动模式。模态启动但电子邮件永远不会到达地址,我检查了邮件枪,但没有错误。
这是我的表格和模态
<form class="form" id="contact-form" action="contactus" method="post">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" name="name" id="name" placeholder="Enter your name" required>
</div>
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" class="form-control" name="email" id="email" placeholder="Enter your email" required>
</div>
<div class="form-group">
<label for="topic">Title</label>
<input type="text" class="form-control" name="topic" id="topic" placeholder="Enter the Title" required>
</div>
<div class="form-group">
<label for="details">Details</label>
<textarea class="form-control" name="details" id="details" placeholder="In a few words let us know how we might be of service" maxlength="2000" required></textarea>
{{ csrf_field() }}
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Welcome Back!</h4>
</div>
<!-- Modal Body -->
<div class="modal-body">
<h1>Hello Readers!</h1>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
这是我的控制器代码
public function contactUs(Request $request)
{
Mail::to($request->email)->send(new ContactUsNotification($request->name));
$contactus = new ContactUs;
dd($request->input);
$contactus->name = $request->input['name'];
$contactus->email = $request->input['email'];
$contactus->topic = $request->input['topic'];
$contactus->message = $request->input['details'];
$contactus->save();
$data = $request->input['name'];
return response()->json($data, 200, [], JSON_PRETTY_PRINT);
}
然后这是我的js,只有在文档加载后才会触发
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('[name="_token"]').val()
}
});
e.preventDefault(e);
$.ajax({
type: 'POST' ,
url: '/contactus',
data: $(this).serializeArray(),
datatype: 'json',
delay: 2000,
success: function(data) {
var options = {
backdrop: true,
keyboard: false,
show: true,
remote: false
};
$("#myModal").modal(options);
console.log(data);
},
error: function(data) {
console.log("Many problems ",data);
}
})
我很感激这方面的帮助