首页 > 解决方案 > 提交按钮进入白屏

问题描述

我已经制作了一个联系表格,当点击提交并填写完整的表格时,屏幕只是变白,页面上的链接从contact.html变为contactform.php。

<?php
    if (isset($_POST['submit'])) {
      $name = $_POST['name'];
      $subject = $_POST['subject'];
      $mailFrom = $_POST['mail'];
      $message = $_POST['message'];

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

      mail($mailTo, $subject, $txt, $headers);
      header("Location: index.php?mailsend");
    }
?>

<div>
  <img src="images/contact.jpg" alt="" class="background-contact">

  <div class="contact-box">
    <br>
    <p class="contact-text-tp">Email</p>

      <form class="contact-form" action="contactform.php" method="post">
        <br>
        <input type="text" name="name" placeholder="Full name">
        <br>
        <input type="text" name="mail" placeholder="Your email">
        <br>
        <input type="text" name="subject" placeholder="Subject">
        <br>
        <textarea name="message" placeholder="Message"></textarea>
        <br>
        <button type="submit" name="Submit">Send email</button>
      </form>
      <br>
    <p class="contact-text-btm">If you would like to directly email please use; <br> email@outlook.com</p>
  </div>

</div>

标签: phphtml

解决方案


因此,首先您需要将页面从 to 重命名contact.htmlcontact.php更改您的代码,如下所示

<?php
    if (isset($_POST['submit'])) {
      $name = $_POST['name'];
      $subject = $_POST['subject'];
      $mailFrom = $_POST['mail'];
      $message = $_POST['message'];

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

      if(mail($mailTo, $subject, $txt, $headers)){
         echo 'success';
      }else{
        echo 'failure';
      }
    }
?>

<div>
  <img src="images/contact.jpg" alt="" class="background-contact">

  <div class="contact-box">
    <br>
    <p class="contact-text-tp">Email</p>

      <form class="contact-form" action="" method="post">
        <br>
        <input type="text" name="name" placeholder="Full name">
        <br>
        <input type="text" name="mail" placeholder="Your email">
        <br>
        <input type="text" name="subject" placeholder="Subject">
        <br>
        <textarea name="message" placeholder="Message"></textarea>
        <br>
        <button type="submit" name="Submit">Send email</button>
      </form>
      <br>
    <p class="contact-text-btm">If you would like to directly email please use; <br> email@outlook.com</p>
  </div>

</div>

推荐阅读