我正在尝试使用ajax调用在laravel中发送邮件。
AJAX
$(".btn-submit").click(function(e){
e.preventDefault();
var name = $("input[name=name]").val();
var email = $("input[name=email]").val();
var subject = $("input[name=subject]").val();
var msg = $("#message").val();
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type:'POST',
url:'/contact',
data:{name:name, email:email, subject:subject, msg:msg},
contentType:'application/json',
success:function(data){
console.dir(data);
},
fail:function(data){
alert(data);
}
});
});
控制器
public function ajaxRequestPost(Request $request){
$name = $request->input('name');
$email = $request->input('email');
$subject = $request->input('subject');
$msg = $request->input('msg');
Mail::send('emails.contact-message',[
'name' => $name,
'email' => $email,
'subject' => $subject,
'msg' => $msg
], function($mail) use ($request){
$mail->from($request->email, $request->name);
$mail->to('validemail@gmail.com')->subject('Subject');
});
return response()->json(['name'=>$name, 'email'=>$email, 'subject'=>$subject, 'msg'=>$msg]);
}
使用这些时,我收到500个内部服务器错误。但是,我不知道MAIL :: SEND有什么错误,因为它在另一个项目中效果很好 有什么我想念的吗?