当用户输入联系方式并按“提交”按钮时,我的联系表不发送电子邮件。我在做什么错了?
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");
}?>
如何解决此问题,以便在按下按钮时发送电子邮件?谢谢。
答案 0 :(得分:1)
您正在检查名为seen
的表单元素:
submit
但是您没有一个名为 if (isset($_POST['submit'])){
的名字。只是 type submit
。给它起个名字:
submit
在发布表单时发送给服务器的键/值对中,元素的<button type="submit" name="submit" class="btn btn-2">Send Enquiry</button>
属性是键。没有名称,它不会发送到服务器。