PHP联系表单,已检查错误不再显示

时间:2017-05-08 22:01:35

标签: php html forms email contact

标题几乎说明了一切。我最初得到一个500内部错误,之前在某些行上的索引错误。我设法让代码不再显示错误,但我仍然没有收到任何电子邮件,也没有收到错误。因此,我有点不知道下一步该怎么做。

当我点击提交按钮时,我的屏幕变为白色。这就是字面意思。 任何帮助,我都非常感激。

这是我的HTML代码:

<section>
<form method="post" action="img/index.php"> <!-- Start Contact Form Actions-->
    <div class="field half first">
        <label for="name">Name</label>
        <input type="text" name="name" id="name" /> <!-- Name Attribute Needed Here For PHP Form-->
    </div>
    <div class="field half">
        <label for="email">Email</label>
        <input type="text" name="email" id="email" /> <!-- Name Attribute Needed Here For PHP Form-->
    </div>
    <div class="field">
        <label for="message">Message</label>
        <textarea name="message" id="message" rows="5"></textarea> <!-- Name Attribute Needed Here For PHP Form-->
    </div>
    <ul class="actions">
        <li><a href="" class="button submit" name="submit">Send Message</a></li>
    </ul>
</form>
</section>

这是我的PHP代码:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

  if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: TangledDemo'; 
    $to = 'team@abc.com'; 
    $subject = 'Hello';
    $body = "From: $name\n E-Mail: $email\n Message:\n $message";
    if (mail ($to, $subject, $body, $from)) { 
      echo '<p>Your message has been sent!</p>';
    } else { 
    echo '<p>Something went wrong, go back and try again!</p>'; 
    }
  }
?>

0 个答案:

没有答案