Php Contact Form

contact form php
Contact Form Php

Contact HTML

<form method="post" action="contact.php" name="contactform" id="contactform">
<div class="enquiry-form">
  <div class="label">  Name  </div>
  <div class="inputs">
    <input type="text" size="40" class="" id="name" value="" name="name">
  <div class="label"> Your phone number </div>
  <div class="inputs">
    <input type="text" size="40" class=" " id="phone" value="" name="phone">
  <div class="label"> Your e-mail address </div>
  <div class="inputs"><span class="">
    <input type="text" size="40" class=" " id="email" value="" name="email">
      <div class="label">Subject </div>
  <div class="inputs">
    <input type="text" size="40" class=" " id="subject" value="" name="subject">
  <div class="label"> Your message </div>
  <div class="inputs"><span class="">
    <textarea rows="10" cols="40" class="" id="comments" name="comments"></textarea>
  <div class="submits">
<button type="submit" class="submit-button" id="submit" name="submit">Send</button>

Contact Php


if(!$_POST) exit;

// Email address verification, do not edit.
function isEmail($email) {

if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");

$name     = $_POST['name'];
$email    = $_POST['email'];
$phone   = $_POST['phone'];
$subject  = $_POST['subject'];
$comments = $_POST['comments'];
$verify   = $_POST['verify'];

if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
else if(trim($comments) == '') {
echo '<div class="error_message">Attention! Please enter your message.</div>';
else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have entered an invalid e-mail address. Please try again.</div>';

if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);

// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "";

//$address = "";
$address = "";

// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."

// Example, $e_subject = '$name . ' has contacted you via Your Website.';

$e_subject = 'You have been contacted by ' . $name . '.';

// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.

$e_body = "You have been contacted by ". $name . " with regards to ".$subject .", their additional message is as follows. \n\n";
$e_content = $comments;
$e_reply = "\n\nYou can contact ". $name ." \n via email, " . $email ." or via phone.". $phone;

$msg = wordwrap( $e_body . $e_content . $e_reply);

$headers  = 'MIME-Version: 1.0' . "\r\n";
//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To:' . $address ."\r\n";
$headers .= 'From: '.$name. ' <'.$address.'>' . "\r\n";
header( "refresh:5;url=contact.html" );

if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.

echo "<div id='success_page'>";
echo "<h1 class='success-message'>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";

} else {

echo 'ERROR!';



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s