When i select 'submit' for this Contact Form, field info doesn't send/arrive. All I see when the email arrives is Name: and Email: <?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."; } ?> Code (markup): Any help with getting the filled-in Form field information to be captured/sent, will be appreciated.
You're reusing the $_POST-variables a lot, while simultaneously attaching them to named variables, and also, what's the point of doing all that validating and stuff up top, when you don't use any of those variables later? Regardless, without seeing the actual form you're fetching these values from, it's hard to help. I'm guessing that there is something in the form that isn't up to scratch.
It's not just the message that is empty, the name as well - which either means the POST-variables aren't there (wrong code in the form), or there is another issue (which might be visible in the PHP-error-log).
Thanks for your replies. This is not my code. Someone else provided it to help me and I'm just trying to get it to work. Currently I removed these lines from the php code: $email = $_POST['email']; $name = $_POST['name']; $message = $_POST['message']; $message = "Name: {$_POST['name']}\r\nEmail: {$_POST['email']}\r\n\r\n{$_POST['message']}"; Code (markup): So, now it looks like this: <?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"; if (mail($to, "Customer Inquiry", $message)) { echo "Thank You. Your message has been sent."; } else { echo "An error has occurred and your message could not be sent."; } ?> Code (markup): And now it successfully sends the info that is entered into the 'message' field. If I can get some help in how to get the info entered into the 'name' and 'email' fields to send/arrive, I'd greatly appreciate any assistance. The person that suggested I remove those lines said "don’t send POST vars". and "you are sending a JSON string". He suggested something to do with the mail command.