联系表单提交无响应

时间:2018-05-07 10:30:31

标签: php

我遇到联系表单的问题,当我尝试提交表单时,它没有响应,请帮我解决这个问题。下面是代码

HTML:

   <form action="contact-form-handler.php" method="post" 
    class="contactForm">
          <div class="row">
            <div class="span4 form-group field">
              <input type="text" name="name" placeholder="Your Name" data- 
                rule="minlen:4" data-msg="Please enter at least 4 chars" />
              <div class="validation"></div>
            </div>

            <div class="span4 form-group">
              <input type="email" name="email" placeholder="Your Email" 
                data-rule="email" data-msg="Please enter a valid email" />
              <div class="validation"></div>
            </div>

            <div class="span8 form-group">
           <textarea name="message" rows="5" data-rule="required" data- 
           msg="Please write something for us" placeholder="Message"> 
           </textarea>
              <div class="validation"></div>
              <div class="text-center">
                <button class="btn btn-success" type="submit" 
             value="sendmessage">Send message</button>

请在提交表单中找到以下php代码,请给我解决方案如何解决此问题。提前致谢。

        if (isset($_POST['submit'])) {
        $name=$_POST['name'];
        $email=$_POST['email'];
    //  $subject=$_POST['subject'];
        $msg=$_POST['msg'];
          }

       $to='contact@****.my';
       $subject='Contact Form';
       $message="Name: " .$name."\n"."email: " .$email."\n"."Subject: " 
      .$subject."\n". "Wrote the following: "."\n\n".$msg;
       $headers="From:".$email;

      if (mail($to, $subject, $message, $headers)) {
      echo "<h1>Your message has been sent. Thank you!"."".$name.", We Will 
      Contact you shortly</h1>";
      }
     else {
      echo "Something went wrong!";
       } 

2 个答案:

答案 0 :(得分:0)

您忘记关闭表单并且没有给您的提交按钮命名,因此您的php无法正常工作

<form action="contact-form-handler.php" method="post" 
    class="contactForm">
          <div class="row">
            <div class="span4 form-group field">
              <input type="text" name="name" placeholder="Your Name" data- 
                rule="minlen:4" data-msg="Please enter at least 4 chars" />
              <div class="validation"></div>
            </div>

            <div class="span4 form-group">
              <input type="email" name="email" placeholder="Your Email" 
                data-rule="email" data-msg="Please enter a valid email" />
              <div class="validation"></div>
            </div>

            <div class="span8 form-group">
           <textarea name="message" rows="5" data-rule="required" data- 
           msg="Please write something for us" placeholder="Message"> 
           </textarea>
              <div class="validation"></div>
              <div class="text-center">
                <button class="btn btn-success" type="submit" name="submit"
             value="sendmessage">Send message</button>
</form>

你忘了关闭这个改变来自

$message="Name: " .$name."\n"."email: " .$email."\n"."Subject: " 

$message="Name: " .$name."\n"."email: " .$email."\n"."Subject: " ;

答案 1 :(得分:0)

$msg=$_POST['msg']; 

必须是

$msg=$_POST['message'];

.$subject."\n". "Wrote the following: "."\n\n".$msg;

必须是

$subject."\n". "Wrote the following: "."\n\n".$msg;