Support Forums

Full Version: Contact Form
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Credits and Source: http://www.roscripts.com/

Name: Contact Form
Description: A simple contact form written in php.
Snippet:

PHP Code:
<?php 
//------ Edit Below This Line ------// 
 
$recipient 'youremail@address.com'
$from 'From: Your Site Name'
 
$namemin 3// Minimum number of characters in name. 
$contentmin 15// Minimum number of words in content. 
$sub = array('Comment''Complaint''Suggestion''Other'); 
 
//------ Edit Above This Line ------// 
 
$name strip_tags(trim(stripslashes($_POST['name']))); 
$email strip_tags(trim(stripslashes($_POST['email']))); 
$subject $_POST['subject']; 
$content htmlspecialchars(trim(stripslashes($_POST['content']))); 
 
$success "<h2>Thank You!</h2>Thank you for filling out the form!"
$errors = array(); 
 
if (isset(
$_POST['submit'])) 

  function 
checkEmail($email
  { 
    if (
preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/"$email)) 
    { 
      
$domain array_pop(explode("@",$email)); 
      if (
gethostbyname($domain) != $domain
      { 
        return 
true
      } 
      return 
false
    } 
    return 
false
  } 
 
  if (!
eregi("^[a-z[:space:]]{{$namemin},}$"$name)) 
    
$errors[] = "Your name must contain at least $namemin letters."
  if (!
checkEmail($email)) 
    
$errors[] = 'You must have a valid email address.'
  if (
$subject == -|| !in_array($subject$sub)) 
    
$errors[] = 'You must choose a subject.'
  if (
str_word_count($content) < $contentmin
    
$errors[] = "Your submission must contain at least $contentmin words."

 
if (!empty(
$errors) || $_SERVER['REQUEST_METHOD'] != 'POST'

  if (!empty(
$errors)) 
  { 
    foreach (
$errors as $error
    { 
      echo 
"<b>$error</b><br />"
    } 
  } 
 
  echo 
'<p><form method="post"><table> 
  <tr><td>Name:</td><td><input type="text" name="name" value="' 
$name '" size="30"></td></tr> 
  <tr><td>Email:</td><td><input type="text" name="email" value="' 
$email '" size="30"></td></tr> 
  <tr><td>Subject: </td><td><select name="subject"> 
  <option value="-1">-Select-</option>'

 
  foreach (
$sub as $type
  { 
    
$selected = ($subject == $type) ? 'selected="selected"' ''
    echo 
"<option $selected>$type</option>"
  } 
 
  echo 
'</select></td></tr> 
  <tr><td>Content:</td><td><textarea name="content" rows="6" cols="40">' 
$content '</textarea></td></tr> 
  <tr><td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td></tr> 
  </table></form></p>'


else 

  
$msgsubject "Feedback: $subject"
  
$msg "Contact Form 
 
------------------------------ 
 
Name: 
$name 
Email: 
$email 
Subject: 
$subject 
 
Content: 
$content 
 
------------------------------"

 
  
mail($recipient$msgsubject$msg$from); 
  echo 
$success

?>


Thankyou for reading. Be happy always Smile