My contact form does not send an email when the user inputs their contact details and presses the submit button. What am I doing wrong?
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");
}?>
How can I fix this, so that on button press, an email is sent? Thank you.
You're checking for a form element named submit
:
if (isset($_POST['submit'])){
But you don't have one named submit
. Just the type submit
. Give it a name:
<button type="submit" name="submit" class="btn btn-2">Send Enquiry</button>
In the key/value pairs sent to the server when posting a form, the element's name
attribute is the key. Without a name, it's not sent to the server.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.