PHP:交互式联系表单不起作用

时间:2017-01-14 18:11:26

标签: php forms email

为什么此表单不起作用?

我正在创建一个向用户发送消息的表单。

用户电子邮件来自数据库。 搜索数据库的查询受先前发送到浏览器的一些数据的影响。

目前的问题是: 当点击提交时,没有任何事情发生。

有一个名为mini-contact.php的文件,其中包含以下内容:

处理表单的脚本:

<?php
var_dump($_POST);
error_reporting(E_ALL);
$company=$_GET['company'];
$sql = "SELECT * FROM companies WHERE companies.companyID= '$company'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
    $row = mysqli_fetch_assoc($result);
    $companyemail = $row['Email_Address'];
    if(isset($_POST['submit'])){
        $to = "tiagomartinsperes@gmail.com"; // this is your Email address
        $from = $_POST['email']; // this is the sender's Email address
        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $subject = $_POST['subject'];
        $subject2 = "Copy of your form submission";
        $message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
        $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

        $header = "From:" . $from; 
        $header.= "MIME-Version: 1.0\r\n"; 
        $header.= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
        $header.= "X-Priority: 1\r\n";

        $header2 = "From:" . $to;
        $header2.= "MIME-Version: 1.0\r\n"; 
        $header2.= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
        $header2.= "X-Priority: 1\r\n";

        $status1 = mail($to,$subject,$message,$header);
        $status2 = mail($from,$subject2,$message2,$header2); // sends a copy of the message to the sender

        if($status1 and $status2){
            $first_name = $_POST['first_name'];
            echo 'Mail Sent. Thank you' . $first_name . ', we will contact you shortly.';
        } else {
            echo '<p>Something went wrong, Please try again!</p>';
        }
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
}
?>

实际形式:

<form id="contact-form" method="post" action="">
     <div class="messages"></div>
        <div class="controls">
           <div class="row">
              <div class="col-md-6 col-sm-6 no-left-pad">
                  <div class="form-group">
                      <label>First Name *</label>
                      <input type="text" name="first_name" class="form-control" placeholder="Please enter your first name" required="required" data-error="First name is required.">
                       <div class="help-block with-errors"></div>
                   </div>
              </div>
              <div class="col-md-6 col-sm-6 no-left-pad">
                   <div class="form-group">
                        <label>Last Name *</label>
                        <input type="text" name="last_name" class="form-control" placeholder="Please enter your last name" required="required" data-error="Last name is required.">
                        <div class="help-block with-errors"></div>
                    </div>
               </div>
               <div class="col-md-6 col-sm-6 no-left-pad">
                    <div class="form-group">
                              <label>Email *</label>
                              <input type="email" name="email" class="form-control" placeholder="Please enter your email" required="required" data-error="Valid email is required.">
                              <div class="help-block with-errors"></div>
                            </div>
                          </div>
                          <div class="col-md-6 col-sm-6 no-left-pad">
                            <div class="form-group">
                              <label>Phone</label>
                              <input type="tel" name="phone" class="form-control" placeholder="Please enter your phone">
                              <div class="help-block with-errors"></div>
                            </div>
                          </div>
                        </div>
                        <div class="row">
                          <div class="col-md-12 no-left-pad">
                            <div class="form-group">
                              <label>Subject</label>
                              <input type="text" name="subject" class="form-control" placeholder="Example: Service Request ">
                              <div class="help-block with-errors"></div>
                            </div>
                          </div>
                        </div>
                        <div class="row">
                          <div class="col-md-12 no-left-pad">
                            <div class="form-group">
                              <label>Message *</label>
                              <textarea name="message" class="form-control" placeholder="Please enter your message" rows="4" required="required" data-error=" Please enter your message."></textarea>
                              <div class="help-block with-errors"></div>
                            </div>
                          </div>
                          <div class="col-md-12 no-left-pad">
                              <p class="text-muted"><strong>*</strong> These fields are required.</p>
                          </div>
                          <div class="col-md-12 no-left-pad">
                            <input type="submit" class="btn btn-default caps" name="submit" value="Submit">
                          </div>
                        </div>
                      </div>
                    </form>

我做错了什么?

感谢您抽出时间

1 个答案:

答案 0 :(得分:1)

需要正确配置SMPT以使其正常工作。