使用PHP / HTML / CSS的基本联系表

时间:2018-07-19 11:01:12

标签: php html email

最近我想制作基本的联系表格。我被卡住了.. 我有3个文件:contact.php form.php和style.css

contact.php:

    <!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="style.css">
  <title></title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
</head>
<body>
  <section>
    <article>
      <div class="container">
        <form id="contact" action="form.php" method="post">
          <h3>Contact</h3>
          <h4>Contact us today, and get reply with in 24 hours!</h4>
          <fieldset>
            <input type="text" name="name" placeholder="Your name">
          </fieldset>
          <fieldset>
            <input type="text" name="mail" placeholder="Your Email Address">
          </fieldset>
          <fieldset>
            <input type="text" name="site" placeholder="Your Web Site starts with http://">
          </fieldset>
          <fieldset>
            <textarea name="message" placeholder="Type your Message Here...." ></textarea>
          </fieldset>
          <fieldset>
            <button type="submit" name="submit" >Submit</button>
          </fieldset>
        </form>
      </div>
    </article>
  </section>
</body>
</html>

form.php

<<?php 

if (isset($_POST['submit'])) {
  $name = $_POST['name'];
  $mail = $_POST['mail'];
  $site = $_POST['site'];
  $message = $_POST['message'];


  $mailTo = "info@example.co";
  $headers = "From: ".$mail;
  $txt = "You have received an e-mail from email".$name.".\n\n".$message;

  mail($mailTo, $name, $txt, $headers, );
  header("Location: contact.php?mailsend");
}

style.css并不重要,因为它正在运行。我的代码有什么问题?我将文件放在站点上的服务器上,并出现错误提示。 “ HTTP错误500”

感谢帮助。

1 个答案:

答案 0 :(得分:-2)

您具有以下条件:

<<?php 

这意味着<将被输出到浏览器。一旦开始输出(HTTP请求正文),便无法再发送HTTP标头。

删除它,标题调用应该起作用。

此外,邮件呼叫中还有一个逗号。也将其删除。

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

始终检查您的error_log!它会告诉您确切的行导致了您的错误!