I am writing a wedding website with a basic form to get the guest email address, guest name(s), guest dinner option, the number of children they are bringing, and a requested song they would like played. I then want to take these values and send them via PHP mail function to an email address. Here is what I have so far:
Here is the snippet of my javascript. The variables emailAddr, g1_name, and g1_dinner all have the correct values in them when I log it to the console.
var data = {
email : emailAddr,
g1Name : g1_name,
g1Dinner : g1_dinner
};
$.post("email.php", data, function(){
alert("Email Success");
});
Here is the PHP:
<?php
$to = "test@email.com";
$from = $_POST['email'];
$guestName_1 = $_POST['g1Name'];
$guestDinner_1 = $_POST['g1Dinner'];
$message = "Email: "+$from +"
Guest 1: "+$guestName_1+" - "+$guestDinner_1;
$message = wordwrap($message, 70);
mail($to,"Wedding RSVP",$message);
?>
Here is what is actually getting POST'd:
And here is the email I get from my web host:
So my main question is why is what is getting POST to my PHP file different than I am specifying?
And a follow up, why am I getting emailed a 0 and not the string I set?
And is this the right way to do something like this?
Any help is appreciated! Thanks!