【问题标题】:Basic contact form using PHP/HTML/CSS [duplicate]使用 PHP/HTML/CSS 的基本联系表格 [重复]
【发布时间】:2018-07-19 11:01:11
【问题描述】:

最近我想制作基本的联系表格。我卡住了。。 我有 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”

感谢您的帮助。

【问题讨论】:

  • &lt;&lt;?php 也许?
  • &lt;&lt;?php 真的有 2 个&lt; 吗?还要检查您的日志。
  • mail() 中还有一个尾随逗号;投票认为这是一个错字。
  • mail($mailTo, $name, $txt, $headers, ); 缺少参数。
  • @TechDad mail() 可以使用 5 个参数,但第 5 个参数完全不同 - 根据 php.net/manual/en/function.mail.php bool mail ( string $to , string $subject , string $message [, mixed $additional_headers [, string $additional_parameters ]] ) 并查看 additional_parameters (optional) 和关于-f sendmail 选项。

标签: php html email


【解决方案1】:

你有以下:

<<?php 

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

删除它,标题调用应该可以工作。

此外,邮件呼叫中还有一个额外的逗号。也删除它。

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

始终检查您的error_log!它会告诉您是哪一行导致了您的错误!

【讨论】:

  • 我删除了一个&lt; 和额外的逗号。脚本工作我得到contact.php?mailsend,但我没有在我的电子邮件中收到消息。我检查并输入了正确的电子邮件地址。
  • 检查您在 php.ini 中的 sendmail_path 设置,确保其配置正确。还要仔细检查它没有被移到垃圾邮件中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-11
  • 2015-06-17
  • 2021-01-22
相关资源
最近更新 更多