This Contact Form submits and shows the “success” message, but the only thing that appears to be sent is:
name:
email:
If you can suggest why no other info is being sent, I’d greatly appreciate any guidance.
[CODE]
<script>
$(function () {
var form = $(“#ajax-contact”);
form[0].reset();
form.submit(function (event) {
event.preventDefault();
var data = {
“name”: $(“#contact-name”).val(),
“email”: $(“#contact-email”).val(),
“message”: $(“#contact-message”).val()
};
$.ajax({
url: “../contact_form_handle.php”,
data: JSON.stringify(data),
contentType: “application/json; charset=utf-8”,
dataType: “text”,
type: “POST”})
.done(function (response) {
$(“#form-response”).text(response);
form[0].reset();
})
.fail(function (data) {
if (data.responseText.length) {
$(“#form-response”).text(data.responseText);
} else {
$(“#form-response”).text(“An error has occurred and your message could not be sent.”);
}
})
});
});
</script>
<form id=”ajax-contact” method=”post”>
<table class=”table10″>
<tr>
<td>
<label for=”name”>Your Name:</label>
<input id=”contact-name” type=”text” name=”name” required>
</td>
</tr>
</tr>
<tr>
<td>
<label for=”email”>Your Email Address:</label>
<input id=”contact-email” type=”email” name=”email” required>
</td>
</tr>
<tr>
<td>
<label for=”message”>Message:</label>
<textarea id=”contact-message” type=”text” name=”message” required></textarea>
</td>
</tr>
<tr>
<td>
<button type=”submit”>Send</button>
</td>
</table>
</form>
<div id=”form-response”></div>
<?php
$data = json_decode(file_get_contents(“php://input”));
$name = trim($data->name);
$name = str_replace(array(“r”, “n”), array(” “, ” “), $name);
$email = filter_var(trim($data->email), FILTER_SANITIZE_EMAIL);
$message = trim($data->message);
if (empty($name) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo “One or more invalid entries. Please try again.”;
exit;
}
$to = “support@…com”;
$from = “From: contact-form@…com”. “rn”;
$email = $_POST[’email’];
$name = $_POST[‘name’];
$message = $_POST[‘message’];
$message = “name: {$_POST[‘name’]}rnemail: {$_POST[’email’]}rnrn{$_POST[‘message’]}”;
if (mail($to, “Customer Inquiry”, $message, $from)) {
echo “Thank You. Your message has been sent.”;
} else {
echo “An error has occurred and your message could not be sent.”;
}
?>