Reputation: 1
My php Contact Form on my website isn't working. The template is from bootstrap. How do i get/build the PHP/AJAX needed for my form to work correctly? What else am i missing? This is my contact.php form. I welcome any feedback! Thanks
<?php
if(!empty($_POST["send"])) {
$name = $_POST["Name"];
$email = $_POST["Email"];
$subject = $_POST["subject"];
$content = $_POST["content"];
$toEmail = "[email protected]";
$mailHeaders = "From: " . $name . "<". $email .">\r\n";
if(mail($toEmail, $subject, $content, $mailHeaders)) {
$message = "Your contact information is received successfully.";
$type = "success";
}
}
require_once "contact-view.php";
?>
Here's a copy of my contact.html code
<div class="col-lg-6">
<form action="forms/contact.php" method="post" role="form" class="php-email-form">
<div class="form-row">
<div class="col-md-6 form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validate"></div>
</div>
<div class="col-md-6 form-group">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validate"></div>
</div>
</div>
<div class="form-group">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
<div class="validate"></div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
<div class="validate"></div>
</div>
<div class="mb-3">
<div class="loading">Loading</div>
<div class="error-message"></div>
<div class="sent-message">Your message has been sent. Thank you!</div>
</div>
<div class="text-center"><button type="submit">Send Message</button></div>
</form>
</div>
Upvotes: 0
Views: 3814
Reputation: 16061
if(!empty($_POST["send"])) {
Here you check if an input named send
isn't empty.
But your HTML code does not have any input named send
.
Simply add <input type="hidden" name="send" value="1">
somewhere inside the <form>
.
Upvotes: 1