Simple Contact Form

This is source code to create simple contact from, you can use it within your PHP page:

 

<div class="Right">

<h5>Contact Form</h5>

<?

$name = $_REQUEST[name];

$email = $_REQUEST[email];

$subject = $_REQUEST[subject];

$message = $_REQUEST[message];

$to = "youremail@yourdomain.com";

 

if(!preg_match('/@/',$email) || empty($name) || empty($email) || empty($subject) || empty($message))

{

?>

<form action="<?echo $_SERVER['PHP_SELF'];?>" method="post">

<div>Name:</div>

<div><input type="text" name="name" value="<?echo $name;?>" <?if (empty($name)) echo'style="border-color:red;border-width:1px;"';?>/></div>

<div>E-Mail:</div>

<div><input type="text" name="email" value="<?echo $email;?>"  <?if (empty($email) || !preg_match('/@/',$email)) echo'style="border-color:red;border-width:1px;"';?>/></div>

<div>Subject:</div>

<div><input type="text" name="subject" value="<?echo $subject;?>"  <?if (empty($subject)) echo'style="border-color:red;border-width:1px;"';?>/></div>

<div>Message:</div>

<div><textarea name="message" rows="5" cols="20"  <?if (empty($message)) echo'style="border-color:red;border-width:1px;"';?>><?echo $message;?></textarea></div>

<div> </div>

<div><input type="submit" value="Submit" name="submit">

<input type="reset" value="Reset"/>

</div>

</form>

<?

}else {

 

$headers = "From:" . $email;

$message = "New contact\nName : $name\n\nEmail : $email\n\nSubject : $subject\n\nMessage : \n$message\n\n\n---\nForm Provided By:\nWebsterz Web Solution\nhttp://www.websterz.net";

$send = mail($to,$subject,$message,$headers);

if($send)

{

echo '<h1>Thankyou for contacting us</h1>';

}else {echo "Theres an error while sending email.";}

 

}

?>

</div>

 

  • 251 Users Found This Useful
Was this answer helpful?

Powered by WHMCompleteSolution