Hello to everybody! I have created email form with HTML and PHP. Everything works well. I want to do next thing. When somebody click on submit button, that under form appears confirmation sentence. For example, “thanks on message”. I have code, but it takes me on other page, when I click on submit button, and I don’t want it. So, when somebody sent mail, I want under email form, confirmation sentence appears. Thanks.
HTML
[code]<div class=”form”>
<form method=”post” name=”emailform” action=”form-to-email.php”>
<input type=”text” name=”name” placeholder=”Your Name”>
<input type=”email” name=”email” required=”” placeholder=”Your Email”>
<input type=”text” name=”phone” placeholder=”Your Phone”>
<input type=”text” name=”address” placeholder=”Your Address”>
<input required=”” type=”text” name=”date” placeholder=”Your Desired Termin” onfocus=”(this.type=’date’)”>
<textarea placeholder=”Your Message” name=”message” onkeyup=”adjust_textarea(this)”></textarea>
<input type=”submit” class=”send” name=”submit” value=”SEND”>
</form>
</div>/code]
PHP
[code]<?php
ob_start();
if(!isset($_POST[‘submit’]))
{
//This page should not be accessed directly. Need to submit the form.
echo “error; you need to submit the form!”;
}
$name = $_POST[‘name’];
$visitor_email = $_POST[’email’];
$phone = $_POST[‘phone’];
$address = $_POST[‘address’];
$date = $_POST[‘date’];
$message = $_POST[‘message’];
//Validate first
if(empty($name)||empty($visitor_email)||empty($phone))
{
echo “Name,email and telefon are mandatory!”;
exit;
}
if(IsInjected($visitor_email))
{
echo “Bad email value!”;
exit;
}
$email_from = $visitor_email;//<== update the email address
$email_subject = “Message from $name”;
$email_body = “Your message has been successfully sent to Woodcity using online contact form. “.
“Here is the message:n $message n”.
“Here is my address:n $address n”.
“Here is my phone:n $phone n”.
“Here is my wanted date:n $date n”.
$to = “[email protected], $visitor_email”;//<== update the email address
$headers = “From: $email_from rn”;
$headers .= “Reply-To: $visitor_email rn”;
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header(‘Location: form confirmation.html’);
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array(‘(n+)’,
‘(r+)’,
‘(t+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(‘|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>/code]