联系表格:电子邮件未发送

当用户输入他们的联系方式并按下提交按钮时,我的联系表单不会发送电子邮件。我究竟做错了什么?


HTML:


    <div class="row">

    <form action="mail.php" accept-charset="utf-8" method="post">

    <div class="form-group contacts-form-result">

    <div class="col-xs-12">

    <strong></strong>    

    </div>

    </div>

    <div class="form-group clearfix">

    <div class="col-xs-12 col-md-6">

    <input type="text" placeholder="Your name *" name="name" class="form-control" required>

    </div>

    </div>

    <div class="form-group clearfix">

    <div class="col-xs-12 col-md-6">

    <input type="email" placeholder="Your e-mail address *" name="email" class="form-control" required>

    </div>

    </div>

    <div class="form-group clearfix">

    <div class="col-xs-12">

    <textarea placeholder="Your message *" rows="7" name="message" class="form-control" required></textarea>

    </div>

    </div>

    <div class="form-group clearfix">

    <div class="col-xs-12">

    <button type="submit" class="btn btn-2">Send Enquiry</button>

    </div>

    </div>

    </form>

PHP:


<?php


if (isset($_POST['submit'])){

  $subject = $_POST['subject'];

  $name = $_POST['name'];

  $mailFrom = $_POST['email'];

  $message = $_POST['message'];


  $mailTo = "myemail@email.com";

  $headers = "Enquiry from: ".$mailFrom;

  $txt = "Name: ".$name."\n"."Message: ".$message;


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


 header("Location: success.html?mailsent");


}?>

我该如何解决这个问题,以便在按下按钮时发送电子邮件?谢谢你。


芜湖不芜
浏览 405回答 1
1回答

慕的地6264312

您正在检查名为 的表单元素submit:if&nbsp;(isset($_POST['submit'])){但是你没有一个名为&nbsp;submit.&nbsp;只是类型&nbsp;submit。给它一个名字:<button&nbsp;type="submit"&nbsp;name="submit"&nbsp;class="btn&nbsp;btn-2">Send&nbsp;Enquiry</button>在发布表单时发送到服务器的键/值对中,元素的name属性是键。没有名称,它不会发送到服务器。
打开App,查看更多内容
随时随地看视频慕课网APP