mardi 14 avril 2015

Bootstrap email form not working properly. Is it my html or php?

Is there anything wrong with either my php or my html for my email form? Every time I submit the form online I get a blank page. I'm not sure what else I would have to change since it seems to make sense but I don't know very much about php.



<form class="form-vertical" role="form" method="post" action="index.php">
<fieldset>

<!-- Text input-->
<div class="form-group">
<label class="control-label" for="textinput">Name</label>
<input id="textinput" name="textinput" type="text" placeholder="Enter Name" class="form-control input-md">
</div>

<!-- Text input-->
<div class="form-group">
<label class="control-label" for="Email">Email</label>
<input id="Email" name="Email" type="text" placeholder="Enter Email" class="form-control input-md">
</div>

<!-- Text input-->
<div class="form-group">
<label class="control-label" for="Phone">Phone</label>
<input id="Phone" name="Phone" type="text" placeholder="" class="form-control input-md">
</div>
</section>
</div> <!-- end col-md-4 -->

<div class="col-md-4 message-form">
<section class="wow zoomInUp" data-wow-duration="1.5s" data-wow-delay="0.2s" style="visibility: visible; -webkit-animation-delay: 0.2s; -moz-animation-delay: 0.2s; animation-delay: 0.2s;">
<!-- Textarea -->
<div class="form-group">
<label class="control-label" for="Message">Message</label>

<textarea class="form-control" rows="5" id="Message" name="Message" placeholder="Message"></textarea>
</div>

<!-- Button -->
<div class="form-group">
<label class="control-label" for="Submit"></label>
<button id="Submit" name="Submit" class="btn btn-primary pull-right">Send Message</button>
</div>
</fieldset>
</form>




<?php
if ($_POST["Submit"]) {
$textinput = $_POST['textinput'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];
$Message = $_POST['Message'];
$from = 'Demo Contact Form';
$to = 'max.henry.campos@gmail.com';
$subject = 'Message from Contact Demo ';

$body = "From: $textinput\n E-Mail: $Email\n Message:\n $Message";

// Check if name has been entered
if (!$_POST['textinput']) {
$errName = 'Please enter your name';
}

// Check if email has been entered and is valid
if (!$_POST['Email'] || !filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}

//Check if message has been entered
if (!$_POST['Message']) {
$errMessage = 'Please enter your message';
}

// If there are no errors, send the email
if (!$errtextinput && !$errEmail && !$errMessage) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! We will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>

Aucun commentaire:

Enregistrer un commentaire