PHP 电子邮件表单重定向到空白页加上发送失败


PHP Email Form Redirects To Blank Page Plus Fails Sending

我只是在这里深入研究一些Web开发。我在索引页中制作了一个表单。我使用了网络上的一些资源来构建此页面。

目前被我构建的表单困住了。此表单位于主页上。PHP电子邮件表单

每次提交时,它都会重定向到一个空白页面,我猜我的 php 页面。

这是表单的代码

编辑的代码

<div class="col-sm-4 form_area">
  <form action="contact_process.php" method="post" class="row m0 appointment_home_form2">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <i class="fa fa-times-circle-o"></i>
    </button>
    <h2 class="title">BOOK<br>NOW</h2>
    <div class="form_inputs row m0">
      <div class="row m0 input_row">
        <div class="col-sm-12 col-md-12 col-lg-6 p0">
          <label for="app_fname">First Name</label>
          <input type="text" class="form-control" id="app_fname" name="contact_fname" placeholder="Your First Name">
        </div>
        <div class="col-sm-12 col-md-12 col-lg-6 p0">
          <label for="app_lname">Last Name</label>
          <input type="text" class="form-control" id="app_lname" name="contact_lname" placeholder="Your Last Name">
        </div>
      </div>
      <div class="row m0 input_row">
        <label for="app_femail">Email Address</label>
        <input type="email" class="form-control" id="app_femail" name="contact_femail" placeholder="Enter your Email Address">
      </div>
      <div class="row m0 input_row">
        <label for="app_fphone">Phone Number</label>
        <input type="tel" class="form-control" id="app_fphone" name="contact_fphone" placeholder="Enter your Phone Number">
      </div>
      <div class="row m0 input_row">
        <label for="app_date">Booking Date</label>
        <div class="input-append date">
          <input type="text" class="form-control" name="date" id="app_date" placeholder="Select the Appointment Date">
          <span class="add-on"><i class="icon-th"></i></span>
        </div>
      </div>
      <div class="row m0 input_row">
        <label for="app_texts">Message</label>
        <textarea id="app_texts" class="form-control" name="contact_fmessage" placeholder="Write down the Message"></textarea>
      </div>
      <input type="submit" class="form-control" value="book your appointment now">
    </div>
    <div class="row m0 form_footer">
      <a href="#">
        <img src="images/call-now3.png" alt="">555 555 5555</a>
    </div>
  </form>
</div>

编辑的 PHP

<?php
    $to = "[myEmail]";
    $from = $_POST['contact_femail'];
    $name = $_POST['contact_fname'];
    $headers = "From: $from";
    $subject = "Hi Doctor, You have a message from" . $from;

    $fields = array();
    $fields["First Name"] = "contact_fname";
    $fields["Last Name"] = "contact_lname";
    $fields["Email"] = "contact_femail";
    $fields["Phone Name"] = "contact_fphone";
    $fields["Message"] = "contact_fmsg";
    $body = "Here is what was sent:'n'n"; foreach($fields as $a => $b){   $body .= sprintf("%20s: %s'n",$b,$_POST[$a]); }
    $send = mail($to, $subject, $body, $headers);
?>

希望我正确格式化了它。尽力让它干净等等。

我看到您在input标签中定义了id属性,但没有像这样定义name属性(这就是它们在您的实际表单 POST 中的显示方式(:

<input type="text" id="app_fname" name="contact_fname" placeholder="Your First Name"/>

此外,考虑到您发送的信息量(以及处理表单提交的常用方法(,您应该在form中定义method属性,如下所示:

<form action="contact_process.php" method="post">