Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\contact-form-submission.php:1) in C:\xampp\htdocs\contact-form-submission.php on line 5
<html>
<form method="POST" action="contact-form-submission.php" class="well smallspace">
Name<br><input type="text" name="name" placeholder="Type you name here" style="width:85%" required><br>
Phone Number<br><input type="Number" name="phnumber" placeholder="Type your phone number" style="width:85%" required/><br>
Email id<br><input type="email" name="emailid" placeholder="Type you email id" style="width:85%" required/><br>
Enter your message<br>
<textarea rows="5" cols="30" name="message" placeholder="Type you message here" style="width:85%" ></textarea><br>
<input type="submit" value="Send" class="btn btn-primary"></input><br><br>
</form>
</html
<?php
// check for form submission - if it doesn't exist then send back to contact form
if (!isset($_POST["save"]) || $_POST["save"] != "contact") {
header("Location: localhost/contact.php"); exit;
}
// get the posted data
$name = $_POST["name"];
$email_address = $_POST["emailid"];
$message = $_POST["message"];
$phone = $_POST["phnumber"];
// check that a name was entered
if (empty ($name))
$error = "You must enter your name.";
// check that an email address was entered
elseif (empty ($email_address))
$error = "You must enter your email address.";
// check for a valid email address
elseif (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", $email_address))
$error = "You must enter a valid email address.";
// check that a message was entered
elseif (empty ($message))
$error = "You must enter a message.";
// check whether a valid phone number
elseif(ereg("^[0-9]{3}-[0-9]{3}-[0-9]{4}$", $phone) )
$error = 'Please enter your valid phone number';
// check if an error was found - if there was, send the user back to the form
if (isset($error)) {
header("Location: contact.php?e=".urlencode($error)); exit;
}
// write the email content
$email_content = "Name: $name\n";
$email_content .= "Email Address: $email_address\n";
$email_content .= "Phone number: $phone";
$email_content .= "Message:\n\n$message";
// send the email
mail ("abc@xyz.com","New Contact Message",$email_content);
// send the user back to the form
header("Location: contact.php?s=".urlencode("Thank you for your message.")); exit;
?>
ab