当用户输入他们的联系方式并按下提交按钮时,我的联系表单不会发送电子邮件。我究竟做错了什么?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:<?phpif (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");}?>我该如何解决这个问题,以便在按下按钮时发送电子邮件?谢谢你。
1 回答
慕的地6264312
TA贡献1817条经验 获得超6个赞
您正在检查名为 的表单元素submit
:
if (isset($_POST['submit'])){
但是你没有一个名为 submit
. 只是类型 submit
。给它一个名字:
<button type="submit" name="submit" class="btn btn-2">Send Enquiry</button>
在发布表单时发送到服务器的键/值对中,元素的name
属性是键。没有名称,它不会发送到服务器。
- 1 回答
- 0 关注
- 404 浏览
添加回答
举报
0/150
提交
取消