Go Back   Dreamweaver Club Forums > Dreamweaver forums > Dreamweaver General
Register FAQ Members List Search Today's Posts Mark Forums Read

Thread Tools Display Modes
Old 02-24-2015, 10:52 AM   #1
Join Date: Oct 2008
Posts: 25
Default Contact form for my website

Hi all
I am trying to have a basic contact form for my website with the following fields

Phone Number
Email Address*

and then Email to my Email address once submitted can anyone help me sort one out please?

I have been trying now for days and I am to the stage of giving up
stu_c is offline   Reply With Quote
Old 02-25-2015, 02:49 AM   #2
edbr's Avatar
Join Date: Aug 2005
Location: Bali
Posts: 11,187

heres one

<?php include 'validation.php';?>
  <title>PHP Contact Form with Validation</title>

	width: 960px;
	height: 610px;
	margin:35px auto;


	width: 350px;
	padding: 10px 50px 30px;
	border: 2px solid gray;
	border-radius: 10px;
	font-family: raleway;

input[type=text],textarea {
	width: 97.7%;
	height: 34px;
	padding-left: 5px;
	margin-bottom: 5px;
	margin-top: 5px;
	border: 2px solid #ccc;
	color: #4f4f4f;
	font-size: 16px;
	border-radius: 5px;


	color: #464646;
	text-shadow: 0 1px 0 #fff;
	font-size: 14px;
	font-weight: bold;

	padding: 10px;
    text-align: center;
    font-size: 18px;
    background: linear-gradient(#ffbc00 5%, #ffdd7f 100%);
    border: 2px solid #e5a900;
    color: #ffffff;
    font-weight: bold;
    cursor: pointer;
    text-shadow: 0px 1px 0px #13506D;
	width: 100%;
	border-radius: 5px;

<div class="container">
  <div class="main">
   <h2>PHP Contact Form with Validation</h2><hr/><br>	
	<form method="post" action="contact_form.php"> 
	<label>Name :</label><br>
	<input class="input" type="text" name="name" value="">
	<span class="error"><?php echo $nameError;?></span><br><br>	
	<label>Email :</label><br>
	<input class="input" type="text" name="email" value="">
	<span class="error"><?php echo $emailError;?></span><br><br>	
	<label>Telephone :</label><br>
	<input class="input" type="text" name="tel" value="">
	<span class="error"><?php echo $telError;?></span><br><br>	
	<label>Message :</label><br>
	<textarea name="message" value=""></textarea>
	<span class="error"><?php echo $messageError;?></span><br><br>	
	<input class="submit" type="submit" name="submit" value="Submit">
    <span class="success"><?php echo $successMessage;?></span>

<!--html ends here-->
validation and mail sender validation.php
// Initialize variables to null.
$name ="";		//Sender Name
$email =""; 	//Sender's email ID
$tel ="";	//Subject of mail
$message ="";	//Sender's Message 

$nameError ="";			
$emailError ="";
$telError ="";
$messageError ="";
$successMessage ="";

//On submitting form below function will execute

  // checking null values in message
    if (empty($_POST["name"])){
        $nameError = "Name is required";
   else {
       $name = test_input($_POST["name"]);
       // check name only contains letters and whitespace
       if (!preg_match("/^[a-zA-Z ]*$/",$name)){
            $nameError = "Only letters and white space allowed"; 
 // checking null values in message  
   if (empty($_POST["email"])) {
       $emailError = "Email is required";
   else {
      $email = test_input($_POST["email"]);
 // checking null values in message    
   if (empty($_POST["tel"])) {
      $telError = "telephone is required";
   else { 
	  $tel = test_input($_POST["tel"]);  
if (!preg_match("/^[1-9][0-9]*$/",$tel )){
            $telError = "Only Numbers allowed"; 

// checking null values in message
   if (empty($_POST["message"])) {
      $messageError = "Message is required";
   else { 
	  $message = test_input($_POST["message"]);  
  // checking null values in all fields  
if( !($name=='') && !($email=='') && !($tel=='') &&!($message=='') )

  {// checking valid email
    if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email) &&(preg_match("/^[1-9][0-9]*$/",$tel ))) {
		$header= $name."<". $to .">";
                $headers = "mydomain.com";
     /* Let's prepare the message for the e-mail */
		$msg = "

 Name: $name
 E-mail: $email
Telephone: $tel
 Message: $message 

/* Send the message using mail() function */
  if(mail($to, $headers, $msg ) )
	$successMessage = "Message sent successfully.......";
  header('Location: thank_you.html/'); 
else { $emailError = "Invalid Email"; }

// function for filtering input values
function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
edit the $to at the top
edit location header on line 80.
i cobbled this quickly but it should do your purpose
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 02:09 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com