My form is not sending the message because of an unexpected error, i cannot see what that error is. It just shows up in a red box and nothing happens to the form. I have looked over the code many times, at first it was looking for the php form in the wrong directory. But now I am stuck.
Website: http://proverbs.io/
Here is my code
The contact section is included through an include.
<?php include 'includes/contact.php';?>
<section class="cta text-center">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h2>Have a suggestion? <span class="highlight">We appreciate feedback!</span></h2>
<p><button class="btn contact-button" type="button" role="button">Contact us</button></p>
<div class='contact-form'>
<form action="php/mail.php" method="POST" role="form">>
<div class='name'>
<input class='form-control first' placeholder='First Name' type='text' autofocus
data-validation-type="string" id="form-name" placeholder="Full Name" name="name">
<input class='last' placeholder='Last Name' type='text' name="last_name">
</div>
<div class='contact'>
<input class='form-control email' placeholder='E-mail Address' type='text' id="form-email" name="email">
</div>
<div class='message'>
<textarea class="form-control" placeholder='Your message' id="form-message" name="message" maxlength="999" style="resize:none"></textarea>
</div>
<div id="success"></div> <!-- For success/fail messages -->
<footer class="submit-button">
<button type="submit">Submit</button>
</footer>
</form>
</div>
</div>
</div>
</div>
</section>
<?php
$email_to = "[email protected]";
$email_from = "[email protected]";
$email_subject = "Contact Form submitted";
if(isset($_POST['email']))
{
function return_error($error)
{
echo $error;
die();
}
// check for empty required fields
if (!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['message']))
{
return_error('incomplete');
}
// form field values
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$message = $_POST['message']; // required
// form validation
$error_message = "Something went wrong. Just email [email protected]";
// name
$name_exp = "/^[a-z0-9 .\-]+$/i";
if (!preg_match($name_exp,$name))
{
$this_error = 'Please enter a valid name.';
$error_message .= ($error_message == "") ? $this_error : "<br/>".$this_error;
}
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if (!preg_match($email_exp,$email))
{
$this_error = 'Please enter a valid email address.';
$error_message .= ($error_message == "") ? $this_error : "<br/>".$this_error;
}
// if there are validation errors
if(strlen($error_message) > 0)
{
return_error($error_message);
}
// prepare email message
$email_message = "Form details below.\n\n";
function clean_string($string)
{
$bad = array("content-type", "bcc:", "to:", "cc:", "href");
return str_replace($bad, "", $string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Message: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($email_to, $email_subject, $email_message, $headers))
{
echo 'success';
}
else
{
echo 'error';
die();
}
}
else
{
echo 'incomplete';
die();
}
?>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments