$("#contact-us-form").submit(function () {
var nameVal = $("input[name=name]").val();
var companyVal = $("input[name=company]").val();
var titleVal = $("input[name=title]").val();
var emailVal = $("input[name=email]").val();
var phoneVal = $("input[name=phone]").val();
var messageVal = $("input[name=message]").val();
alert(nameVal);
alert(emailVal);
$.post("/mailer.php", {
name: nameVal,
company: companyVal,
title: titleVal,
email: emailVal,
phone: phoneVal,
message: messageVal
}, function (data) {
alert("Data Loaded: " + data);
$('#thanks').show();
});
});
mailer.php in in root, and it contains:
<?php
if(isset($_POST['submit'])) {
$to = "[email protected]";
$subject = "Inquiry";
$name = $_POST['name'];
$company = $_POST['company'];
$title = $_POST['title'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$body = <<<HEREDOC
From: $name
Company: $company
Title: $title
E-Mail: $email
Phone: $phone \n
Message: $message
HEREDOC;
mail($to, $subject, $body);
}
?>
I see the name
and email
alerts with correct data, but the data alert is empty, just shows Data Loaded:
, so I'm guessing that the data is not submitted correctly.
How do I fix it?
Many thanks!