Bootstrap Contact Form server not responding

我与影子孤独终老i 提交于 2019-12-12 04:34:17

问题


I am trying to get my contact form to work, but when I fill out the form, it throws out a server not responding error.

You can view the JSFiddle here: JS & HTML contact form code

The contact_me.php code:

<?php

error_reporting(E_ALL); ini_set('display_errors', 1);

// check if fields passed are empty
if(empty($_POST['name'])        ||
   empty($_POST['email'])       ||
   empty($_POST['phone'])       ||
   empty($_POST['message'])     ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
    echo "No arguments Provided!";
    return false;
   }

$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];

// create email body and send it    
$to = 'trisha@trishajohnson.net'; // put your email
$email_subject = "Contact form submitted by:  $name";
$email_body = "You have received a new message. \n\n".
                  " Here are the details:\n \nName: $name \n ".
                  "Email: $email_address\n Phone: $phone\n Message: \n $message";
$headers = "From: no-reply@trishajohnson.net\n";
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;            
?>

I don't see any errors in any of the code, so I'm not quite sure what the issue is.


回答1:


When I visited your page, I noticed the following were missing from the form:

  • The form's action. Forms default to GET when omitted.
  • Missing name elements.

Solution:

  • Add method="post" inside the form.
  • Add the name attribute to the inputs, i.e.: <input type="text" name="name">

Your PHP contains POST variables and POST relies on the name attribute in order to process the form's data.

Sidenote: Your original question did not contain the error reporting, which should be used to check for errors.

Add error reporting to the top of your file(s) which will help find errors.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Sidenote: Error reporting should only be done in staging, and never production.



来源:https://stackoverflow.com/questions/27261939/bootstrap-contact-form-server-not-responding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!