首页 > 解决方案 > 无法让我的联系表实际工作

问题描述

一般来说,我对编码很陌生,刚刚开始尝试将 PHP 用于 uni 项目。

我已经制作了一个非常简单的 HTML 联系表单,并且没有打扰它的样式(因为它只是一个测试)我现在的问题是,我试图让它真正通过它发送电子邮件。PHP。联系表格本身有效,但它只是不会向我在 PHP 中选择的邮件发送电子邮件

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title> Contact form tutorial </title>
</head>

<body>
  <main>
    <p> SEND E-MAIL </p>
    <form class="contact-form" action="contactform.php" method="post">
      <input type="text" name="name" placeholder="Full name">
      <input type="text" name="mail" placeholder="Your e-mail">
      <input type="text" name="subject" placeholder="Subject">
      <textarea name="message" placeholder="Message"></textarea>
      <button type="submit" name="submit"> SEND MAIL </button>
    </form>
  </main>
</body>

</html>

<?php

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

  $mailTo = "hse-g01@haarslev-esport.dk";
  $headers = "From: ".$mailFrom;
  $txt = "You have recieved an e-mail from ".$name.".\n\n".$message;

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

标签: phphtmlemail

解决方案


推荐阅读