I have created an AJAX contact form which sends to MailGun and it works fine but the message does not display for some reason. As you can see from the picture.
This is the HTML template for the e0-mail that is sent to Mailgun:
contact.blade.php
<h3>You have a new contact via the contact form!</h3>
<div>
</div>
<p>Sent via Hell</p>
I don't think the contact.blade.php is picking up the variable.
This is the jQuery for the AJAX form:
$("form.wpcf7-form").submit(function(e){
e.preventDefault();
var token = $("input[name=_token]").val(); // The CSRF token
var first_name = $("input[name=first-name]").val();
var last_name = $("input[name=last-name]").val();
var email = $("input[name=email]").val();
var phone = $("input[name=phone]").val();
var bodyMessage = $("textarea[name=message]").val();
$.ajax({
type:'POST',
url:'/contact',
dataType: 'json',
data:{_token: token, first_name:first_name, last_name:last_name, email:email, phone:phone, bodyMessage:bodyMessage},
success:function(data){
$(".email-success-messge").append(data.success).fadeIn(999);
}
});
});
Here is the ContactController.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Post;
use Mail;
use Session;
class ContactController extends Controller
{
public function postContact(Request $request){
$this->validate($request, ['email' => 'required|email'] );
$data = array(
'first_name' => $request->first_name,
'last_name' => $request->last_name,
'email' => $request->email,
'phone' => $request->phone,
'bodyMessage' => $request->message
);
Mail::send('emails.contact', $data, function($message) use ($data){
$message->from($data['email']);
$message->to('j***r@*********.co.uk');
$message->subject('Contact Details');
});
return response()->json(['success' => 'Your E-mail was sent! Allegedly.'], 200);
}
}
I honestly don't understand why it takes the message details like the sender's email and subject but not the message.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire