<!-- THIS IS USING GOOGLES reCaptcha V2 -->
<?php
if(isset($_POST['ContactButton'])) {
$url = "https://www.google.com/recaptcha/api/siteverify";
$privateKey = "##########################";
$response = file_get_contents($url."?secret=".$privateKey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);
$data = json_decode($response);
if (isset($data->success) AND $data->success==true) {
$error = "";
$successMsg = "";
if ($_POST) {
if ($_POST['email'] && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$error .= "The email is invalid!<br>";
}
if (!$_POST['email']) {
$error .= "An email address is required!<br>";
}
if (!$_POST['subject']) {
$error .= "A subject is required!<br>";
}
if (!$_POST['body']) {
$error .= "Content in the body is required!<br>";
}
if ($error != "") {
$error = '<div class="alert alert-danger" role="alert"><strong>There is an error with your form!</strong><br>' . $error . '</div>';
} else {
$emailTo = 'contactform#########.com';
$subject = $_POST['subject'];
$body = $_POST['body'];
$headers = "From: ".$_POST['email'];
if (mail($emailTo, $subject, $body, $headers)) {
$successMsg = '<div class="alert alert-success" role="alert">The message has successfully been sent. We will contact you ASAP!</div>';
} else {
$error = '<div class="alert alert-danger" role="alert">There was a problem sending your message, please try again later!</div>';
}
}
}
} else {
$captchaFail = '<div class="alert alert-danger" role="alert"><strong>There is an error with your form!</strong><br>reCaptcha Verification Failed, Please Try Again.</div>';
}
}
?>
<div class="jumbotron" id="contact-us-co" style="display: none">
<p>Contact Us:
<br><br>
<form method="POST" class="container">
<h2 style="text-align:center;">***Contact Us***</h2>
<br>
<div id="error"><?php echo $successMsg ?><?php echo $error ?><?php echo $captchaFail ?></div>
<div class="form-row">
<div class="form-group col-md-12">
<label for="inputEmail">Email</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputSubject">Subject</label>
<input type="text" class="form-control" id="subject" name="subject" placeholder="Subject">
</div>
<label for="inputBody">Message</label>
<div class="form-group input-group">
<textarea class="form-control" aria-label="With textarea" placeholder="Body" name="body" id="body"></textarea>
</div>
<div class="g-recaptcha" data-sitekey="###################"></div>
<br>
<button type="submit" class="btn btn-primary" name="ContactButton" id="ContactButton">Submit</button>
</form> </p>
</div>
Solution #1 (not sure how to add this code)
code to prevent refresh:
document.getElementById('ContactButton').addEventListener('click', function(event) {
event.preventDefault();
}, false);
Solution #2
After form refresh reset back to the Contact Page: (I used onClick for behaviors)
Contact Us
It's a default html form behavior. If you want to send form data without page reloading you need to looking for AJAX (or AjaxForm plugin):
F.e:
jQuery AJAX submit form
Related
The below HTML and PHP code executes as expected in Google Chrome - enter the requested data into the form and press send, then a message is sent to an email address and the page is refreshed.
However, the same expected behaviour does not occur in Safari - once the 'send' button is clicked the user is brought to a blank white page (the email.php file).
Can anyone tell me why it does not do as expected in Safari?
HTML Code:
<form method="POST" id="contactForm" name="contactForm" class="contactForm" novalidate="novalidate" action="email.php" onsubmit="this.submit(); this.reset(); return false;">
<div class="row">
<!-- Name Input -->
<div class="col-md-1 col-sm-1">
<div class="form-group">
<label class="contact-text">Name:</label>
</div>
</div>
<div class="col-md-11 col-sm-11 contact-col">
<div class="form-group">
<input type="text" class="form-control" name="name" id="name">
</div>
</div>
<!-- Email Input -->
<div class="col-md-1 col-sm-1">
<div class="form-group">
<label class="contact-text">Email:</label>
</div>
</div>
<div class="col-md-11 col-sm-11 contact-col">
<div class="form-group">
<input type="email" class="form-control" name="email" id="email">
</div>
</div>
<!-- Message Input -->
<div class="col-md-1 col-sm-1">
<div class="form-group">
<label class="contact-text">Message:</label>
</div>
</div>
<div class="col-md-11 col-sm-11 contact-col">
<div class="form-group">
<textarea class="form-control" name="message" id="message" cols="30" rows="6"></textarea>
</div>
</div>
</div>
</div>
</div>
<!-- Submit Button -->
<div class="col-md-8 col-sm-8 col-8 text-end">
<div class="form-group">
<button type="submit" class="btn btn-primary">Send</button>
<div class="submitting"></div>
</div>
</div>
</div>
</form>
PHP Code:
$errors = [];
$errorMessage = '';
if (!empty($_POST)) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if (empty($name)) {
$errors[] = 'Name is empty';
}
if (empty($email)) {
$errors[] = 'Email is empty';
} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Email is invalid';
}
if (empty($message)) {
$errors[] = 'Message is empty';
}
if (empty($errors)) {
$toEmail = 'cillinlyons#outlook.com';
$emailSubject = 'New email from your contant form';
$headers = ['From' => $email, 'Reply-To' => $email, 'Content-type' => 'text/html; charset=iso-8859-1'];
$bodyParagraphs = ["Name: {$name}", "Email: {$email}", "Message:", $message];
$body = join('<br>', $bodyParagraphs);
if (mail($toEmail, $emailSubject, $body, $headers)) {
header('Location: https://cillinlyons.me');
} else {
$errorMessage = 'Oops, something went wrong. Please try again later';
}
} else {
$allErrors = join('<br/>', $errors);
$errorMessage = "<p style='color: red;'>{$allErrors}</p>";
}
}
?>
you need a name for your button to set it with php
<button type="submit" class="btn btn-primary" name="submit">Send</button>
and use array_push() to have all errors in a array ,
i used isset() for check the submit is clicked or not.
<?php
$errors = [];
$errorMessage = '';
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if (empty($name)) {
array_push($errors, 'Name is empty');
}
if (empty($email)) {
array_push($errors, 'Email is empty');
} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
array_push($errors, 'Email is invalid');
}
if (empty($message)) {
array_push($errors, 'Message is empty');
}
if (empty($errors)) {
$toEmail = 'cillinlyons#outlook.com';
$emailSubject = 'New email from your contant form';
$headers = ['From' => $email, 'Reply-To' => $email, 'Content-type' => 'text/html; charset=iso-8859-1'];
$bodyParagraphs = ["Name: {$name}", "Email: {$email}", "Message:", $message];
$body = join('<br>', $bodyParagraphs);
if (mail($toEmail, $emailSubject, $body, $headers)) {
header('Location: https://cillinlyons.me');
} else {
$errorMessage = 'Oops, something went wrong. Please try again later';
}
} else {
foreach ($errors as $error)
echo "<p style='color: red;'>{$error}</p>";
}}
i tested this on safari and its working
so I'm trying to make the contact form using PHP with validations. So when the input fields are not filled and I click send button it displays the error that says to fill in all blanks but when I fill in everything and click on send button, it sends message to my email address but doesn't display that the message was sent successfully, it just says "page not found" here's my code for contact.php and send.php
<div class="container">
<div class="row text-center">
<div class="col-12 heading">
<h1>Contact Us</h1>
</div>
<div class="col-12">
<?php
$Msg = "";
if(isset($_GET['error'])) {
$Msg = "Please Fill in All Blannks";
echo '<div class="alert alert-danger">'.$Msg.'</div>';
}
if(isset($_GET['success'])) {
$Msg = "Your Message Has Been Sent";
echo '<div class="alert alert-success">'.$Msg.'</div>';
}
?>
</div>
</div>
</div>
<div class="container">
<div class="row text-center">
<div class="col-12">
<form class="reportform" action="send.php" method="post">
<input type="text" name="UName" placeholder="Full Name"><br>
<input type="email" name="Email" placeholder="Your e-mail"><br>
<input type="text" name="Subject" placeholder="Subject"><br>
<textarea name="msg" placeholder="Message"></textarea><br>
<h6>By clicking send button, you agree our <a target="_blank" href="../credits/ppolicy.html">Privacy Policy</a></h6>
<button type="submit" name="btn-send" class="btn btn-primary sendbtn">Send</button>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['btn-send'])){
$UserName = $_POST['UName'];
$Email = $_POST['Email'];
$Subject = $_POST['Subject'];
$Msg = $_POST['msg'];
if(empty($UserName) || empty($Email) || empty($Subject) || empty($Msg)) {
header('location: contact.php?error');
}
else {
$to = "nika.makhatadze17#gmail.com";
if(mail($to,$Subject,$Msg,$Email)) {
header("location: index.php?success");
}
}
}
else {
header("location: contact.php");
}
?>
By Success you redirect to index.php?success but you defined the Success case in your contact.php, so i would say you just have to change header("location: index.php?success"); to header("location: contact.php?success");
Hey try this code we mead some changes on your code
pass success msg value on header location
<div class="container">
<div class="row text-center">
<div class="col-12 heading">
<h1>Contact Us</h1>
</div>
<div class="col-12">
<?php
$Msg = "";
if(isset($_GET['error'])) {
$Msg = "Please Fill in All Blannks";
echo '<div class="alert alert-danger">'.$Msg.'</div>';
}
if(isset($_GET['success'])) {
$Msg = "Your Message Has Been Sent";
echo '<div class="alert alert-success">'.$Msg.'</div>';
}
?>
</div>
</div>
</div>
<div class="container">
<div class="row text-center">
<div class="col-12">
<form class="reportform" action="send.php" method="post">
<input type="text" name="UName" placeholder="Full Name"><br>
<input type="email" name="Email" placeholder="Your e-mail"><br>
<input type="text" name="Subject" placeholder="Subject"><br>
<textarea name="msg" placeholder="Message"></textarea><br>
<h6>By clicking send button, you agree our <a target="_blank" href="../credits/ppolicy.html">Privacy Policy</a></h6>
<button type="submit" name="btn-send" class="btn btn-primary sendbtn">Send</button>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['btn-send'])){
$UserName = $_POST['UName'];
$Email = $_POST['Email'];
$Subject = $_POST['Subject'];
$Msg = $_POST['msg'];
$successMsg = 1;
if(empty($UserName) || empty($Email) || empty($Subject) || empty($Msg)) {
header('location: contact.php?error');
}
else {
$to = "nika.makhatadze17#gmail.com";
if(mail($to,$Subject,$Msg,$Email)) {
header("location: index.php?success=".$successMsg);
}
}
}
else {
header("location: contact.php");
}
I am stumped....
I have created a PHP form to gather some user information and email it to the site owner, after the form is submitted, the fields auto complete with a '1' I am assuming this means the field was true and submitted.
Does anyone have any suggestions on how to hide or remove the 1 after the form is submitted? I just want the form to be blank after submission. Here is the code, Sorry for the poor formatting and eye bleeding wall of code.
Thank you in advance for any help!
PHP Code
$errName = "";
$errcatBreed = "";
$errEmail = "";
$errMessage = "";
$result = "";
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$catBreed = $_POST['catBreed'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'PearTreeHill Contact Form';
$to = 'test#domain.com';
$subject = "New furbaby enquiry from $name";
$body ="From: $name\n Cat Breed: $catBreed\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if cat breed has been entered
if (!$_POST['catBreed']) {
$errcatBreed = 'Please enter either Ragdoll or British ShortHair';
}
// 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';
}
// RECAPTCHA
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response']))
{
$secret = 'Private Key';
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if($responseData->success)
{
$succMsg = 'Your contact request have submitted successfully.';
}
else
{
$errMsg = 'Robot verification failed, please try again.';
}
}
// If there are no errors, send the email
if (!$errName && !$errcatBreed && !$errEmail && !$errMessage) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again.</div>';
}
}
}
HTML Code
<!-- contact form -->
<section id="contactUs" class="bg">
<div class="container">
<div class="row">
<div class="col-lg-8 mx-auto">
<div class="text-center">
<h2 class="w3-tangerine">Contact Us</h2>
</div>
<!-- start of entry form -->
<form class="form-horizontal" role="form" method="post" action="index.php">
<!-- name entry -->
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-12">
<input type="text" class="form-control" id="name" name="name" placeholder="First & Last Name" value="<?php echo htmlspecialchars(isset($_POST['name'])); ?>">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
</div>
<!-- cat breed selection -->
<div class="form-group">
<label for="catBreed" class="col-sm-2 control-label">Cat Breed</label>
<div class="col-sm-12">
<input type="text" class="form-control" id="catBreed" name="catBreed" placeholder="'Ragdoll' or 'British ShortHair'" value="<?php echo htmlspecialchars(isset($_POST['catBreed'])); ?>">
<?php echo "<p class='text-danger'>$errcatBreed</p>";?>
</div>
</div>
<!-- email address entry -->
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-12">
<input type="email" class="form-control" id="email" name="email" placeholder="example#domain.com" value="<?php echo htmlspecialchars(isset($_POST['email'])); ?>">
<?php echo "<p class='text-danger'>$errEmail</p>";?>
</div>
</div>
<!-- Body of message -->
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-12">
<textarea class="form-control" rows="4" name="message" placeholder="Please enter any other information"><?php echo htmlspecialchars(isset($_POST['message']));?></textarea>
<?php echo "<p class='text-danger'>$errMessage</p>";?>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<!-- reCAPTCHA -->
<div class="g-recaptcha" data-sitekey="Public Key" data-callback="recaptcha_callback"></div>
<!-- send button -->
<input disabled="disabled" id="submit" name="submit" type="submit" value="Send Message" class="btn btn-danger">
<label for="submit" class="col-sm-8 control-label">Please allow up to 48 hours for a response!</label>
</div>
</div>
<!-- entry alert -->
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>
</form>
</div>
</div>
</div>
<?php echo htmlspecialchars(isset($_POST['email'])); ?>
Here you display the result of isset() (TRUE or FALSE).
You should do :
<?php if ( isset($_POST['email']) ) echo htmlspecialchars($_POST['email']); ?>
And this for each field :-)
change
echo htmlspecialchars(isset($_POST['name']));
to
echo htmlspecialchars ($_POST['name'])
I mean remove isset();
after sending message on contact form, results shows 404 error instead of success message. I have tried many times, i don't know what is missing. Any help will be very appreciated.
Second issue is also there, it shows:
Uncaught TypeError: $ is not a function
at contact.js?ver=20170915:1
here is the html code
<!-- Start Contact Form -->
<div class="col-lg-4 col-md-5 col-xs-12">
<div class="alert alert-info text-center " role="alert">
<h5>Contact</h5>
</div>
<form id="contact-form" method="post" action="contact.php" role="form">
<form role="form" id="contactForm" class="contact-form" data-toggle="validator">
<div class="form-group">
<div class="controls">
<input type="text" name="name" id="name" class="form-control" placeholder="Name" required data-error="Please enter your name">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<div class="controls">
<input type="email" name="email" class="email form-control" id="email" placeholder="Email" required data-error="Please enter your email">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<div class="controls">
<input type="text" name="msg_subject" id="msg_subject" class="form-control" placeholder="Subject" required data-error="Please enter your message subject">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="form-group">
<div class="controls">
<textarea id="message" rows="3" name="message"placeholder="Massage" class="form-control" required data-error="Write your message"></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<button type="submit" id="submit" class="btn btn-block bg-info">Send Message</button>
<div id="msgSubmit" class="h3 text-center hidden"></div>
<div class="clearfix"></div>
</form>
</div>
</div>
</div>
<!-- Contact Form Section End -->
And i have added contact.php page
<?php
$errorMSG = "";
// NAME
if (empty($_POST["name"])) {
$errorMSG = "Name is required ";
} else {
$name = $_POST["name"];
}
// EMAIL
if (empty($_POST["email"])) {
$errorMSG .= "Email is required ";
} else {
$email = $_POST["email"];
}
// MSG SUBJECT
if (empty($_POST["msg_subject"])) {
$errorMSG .= "Subject is required ";
} else {
$msg_subject = $_POST["msg_subject"];
}
// MESSAGE
if (empty($_POST["message"])) {
$errorMSG .= "Message is required ";
} else {
$message = $_POST["message"];
}
//Add your email here
$EmailTo = "chandanicfai1#gmail.com";
$Subject = "New Message Received";
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Subject: ";
$Body .= $msg_subject;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From:".$email);
// redirect to success page
if ($success && $errorMSG == ""){
echo "success";
}else{
if($errorMSG == ""){
echo "Something went wrong :(";
} else {
echo $errorMSG;
}
}
?>
contact.js file is
$("#contactForm").validator().on("submit", function (event) {
if (event.isDefaultPrevented()) {
// handle the invalid form...
formError();
submitMSG(false, "Did you fill in the form properly?");
} else {
// everything looks good!
event.preventDefault();
submitForm();
}
});
function submitForm(){
// Initiate Variables With Form Content
var name = $("#name").val();
var email = $("#email").val();
var msg_subject = $("#msg_subject").val();
var message = $("#message").val();
$.ajax({
type: "POST",
url: "contact.php",
data: "name=" + name + "&email=" + email + "&msg_subject=" + msg_subject + "&message=" + message,
success : function(text){
if (text == "success"){
formSuccess();
} else {
formError();
submitMSG(false,text);
}
}
});
}
function formSuccess(){
$("#contactForm")[0].reset();
submitMSG(true, "Message Submitted!")
}
function formError(){
$("#contactForm").removeClass().addClass('shake animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
$(this).removeClass();
});
}
function submitMSG(valid, msg){
if(valid){
var msgClasses = "h3 text-center tada animated text-success";
} else {
var msgClasses = "h3 text-center text-danger";
}
$("#msgSubmit").removeClass().addClass(msgClasses).text(msg);
}
and also form validator
https://github.com/1000hz/bootstrap-validator/blob/master/js/validator.js
I have successfully set up a php script for my contact form on my website but I have recently found out that my server provider does not accept php. Instead I have use SMTP.
Can anyone help me as this is new to me. I've attempted using other scripts but I cannot implement it.
This is my php code:
<?php
/* Set e-mail recipient */
$myemail = "mail#louisreed.co.uk";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Your Name");
$email = check_input($_POST['email'], "Your E-mail Address");
$subject = check_input($_POST['subject'], "Message Subject");
$message = check_input($_POST['message'], "Your Message");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\#[\w\-]+\.[\w\-]+)/", $email))
{
show_error("Invalid e-mail address");
}
/* Let's prepare the message for the e-mail */
$subject = "Someone has sent you a message";
$message = "
Someone has sent you a message using your contact form:
Name: $name
Email: $email
Subject: $subject
Message:
$message
";
/* Send the message using mail() function */
mail($myemail, $subject, $message);
/* Redirect visitor to the thank you page */
header('Location: http://louisreed.co.uk');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
My HTML form:
<div class="row">
<div class="col-lg-8 col-lg-offset-2">
<form role="form" action="http://www.louisreed.co.uk/includes/mailer.php" method="post">
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<label for="name">Name</label>
<input class="form-control" type="text" id="name" name="name" placeholder="Name">
</div>
</div>
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<label for="email">Email Address</label>
<input class="form-control" type="email" id="email" name="email" placeholder="Email Address">
</div>
</div>
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<label for="subject">Subject</label>
<textarea placeholder="Subject" class="form-control" id="subject" name="subject" rows="1"></textarea>
</div>
</div>
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<label for="message">Message</label>
<textarea placeholder="Message" class="form-control" id="message" name="message" rows="5"></textarea>
</div>
</div>
<br>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-lg btn-primary">Send</button>
</div>
</div>
</form>
</div>
</div>
Any suggestions welcome!
Thanks! :)
Louis
Oke I checked a few thinks. I guess you could atleast try the following. I know your host doesn't support php which find hard to believe tough. So maybe something else is wrong. What is the host you are using?
<?php
if($_POST) {
//Strip user input
function sanitize($value) {
//Escape the user input and then strip all html tags
//mysql_* is not recommended but I guess you don't store data in a database
$value = mysql_real_escape_string(strip_tags($value));
//Return the sanitized user input
return $value;
}
//To display all errors
function errors($error) {
echo '<ul class="error">';
foreach($error as $fail) {
echo '<li>'.$fail.'</li>';
}
echo '</ul>';
}
//All the input fields
$name = sanitize($_POST['name']);
$email = sanitize($_POST['email']);
$subject = sanitize($_POST['subject']);
$message = sanitize($_POST['message']);
//Check if there are no empty fields
if(!empty($name), !empty($email) && !empty($subject) && !empty($message)) {
if(strlen($name) <= 3) {
$error[] = 'Name '.$name.' is too short';
}
if(strlen($email) <= 3) {
$error[] = 'Email '.$email.' is too short';
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error[] = 'Email '.$email.' is not a valid email';
}
if(strlen($subject) <= 3) {
$error[] = 'Subject '.$subject.' is too short';
}
if(strlen($message) <= 8) {
$error[] = 'Message is too short';
}
//If there are no errors
if(empty($error)) {
$to = "mail#louisreed.co.uk"; //The email you want to send it to
//Subject already set
$headers = "FROM: My site"; //Sets the headers
//The message for the email
$message = "Someone has sent you a message using your contact form:\r\n\r\nName: ".$name."\r\nEmail: ".$email."\r\nSubject: ".$subject."\r\n\r\nMessage: ".$message;
$mail = mail($to, $subject, $message, $headers);
//If the mail has been send
if($mail) {
header('Location: http://louisreed.co.uk/index.php?success');
exit();
}
}
} else {
$error[] = 'There are empty fields';
}
//If there are errors show them
if(!empty($error)) {
echo errors($error);
}
}
//If issset success (from the header()) display a message
if(isset($_GET['success'])) {
echo '<p>Thank you for your message</p>';
}
?>
<form role="form" action="" method="post">
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<label for="name">Name</label>
<input class="form-control" type="text" id="name" name="name" placeholder="Name">
</div>
</div>
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<label for="email">Email Address</label>
<input class="form-control" type="email" id="email" name="email" placeholder="Email Address">
</div>
</div>
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<label for="subject">Subject</label>
<textarea placeholder="Subject" class="form-control" id="subject" name="subject" rows="1"></textarea>
</div>
</div>
<div class="row">
<div class="form-group col-xs-12 floating-label-form-group">
<label for="message">Message</label>
<textarea placeholder="Message" class="form-control" id="message" name="message" rows="5"></textarea>
</div>
</div>
<br>
<div class="row">
<div class="form-group col-xs-12">
<button type="submit" class="btn btn-lg btn-primary">Send</button>
</div>
</div>
</form>
So try the exact code I gave you above just copy and past it over the form code you have now. You can leave the rest of your code as is. After that save the complete file as index.php. After that remove the index.html file from your FTP. If you have done that you can upload the index.php file now check what you get. If there are still some errors please let me know