PHP发送电子邮件但未从HTML表单获取数据

时间:2018-10-06 02:50:25

标签: php html email

我正在尝试从HTML表单获取一些数据,例如姓名,电子邮件等,并将该数据发送到我的gmail。我收到一封电子邮件,上面写着“您已收到来自的电子邮件。”以及“无发件人”和“无主题”作为电子邮件详细信息。

这是PHP:

<?php

if(isset($_POST['submit'])) {
  $name = $_POST['first_name'];
  $subject = $_POST['subject'];
  $mailFrom = $_POST['email'];
  $message = $_POST['message'];

  $mailTo = "tamiroffen@gmail.com";
  $headers = "From: " . $mailFrom;
  $txt = "You have recieved an email from " . $name . ".\n\n" .  $message;

  mail($mailTo, $subject, $txt, $headers);

  header("Location: index.html?mailsend");
}

?>

以下是HTML的表单部分摘要:

<form action="contact_form_process.php" method="POST">
    <section id="contact" class="py-3">
      <div class="container">
        <div class="row">
          <div class="col-md-9 mx-auto">
            <div class="card p-4">
              <div class="card-body">
                <h3 class="text-center lato-font">Please Fill Out This Form To Contact Us</h3>
                <hr>
                <div class="row">
                  <div class="col-md-6">
                    <div class="form-group">
                      <input id="first_name" name="first_name" type="text" class="form-control" placeholder="First Name">
                    </div>
                  </div>
                  <div class="col-md-6">
                    <div class="form-group">
                      <input id="last_name" type="text" class="form-control" placeholder="Last Name">
                    </div>
                  </div>
                  <div class="col-md-6">
                    <div class="form-group">
                      <input id="email" type="text" class="form-control" placeholder="Email">
                    </div>
                  </div>
                  <div class="col-md-6">
                    <div class="form-group">
                      <input id="phone_num" type="text" class="form-control" placeholder="Phone Number">
                    </div>
                  </div>
                  <div class="col-md-12">
                    <div class="form-group">
                      <textarea class="form-control" name="" id="message" rows="10" placeholder="Message"></textarea>
                    </div>
                  </div>
                </div>
              </div>
              <div class="card-footer">
                <button type="submit" name="submit" class="btn btn-outline-success btn-block">Send</button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </form>

0 个答案:

没有答案