Contact Form is not sending all info
Contact Form info is not sending from my PHP/jQuery contact form, only
name:
email:
Here's the code:
<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>
- <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>
- <?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". "\r\n";
- $email = $_POST['email'];
- $name = $_POST['name'];
- $message = $_POST['message'];
- $message = "name: {$_POST['name']}\r\nemail: {$_POST['email']}\r\n\r\n{$_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.";
- }
- ?>
Any help will be appreciated.