Contact form with departments
This has to be one of the easiest PHP scripts that you could get your hands on. Primarily designed for web hosts, you could use this for your main web site as well.

There's only one page and it can fit in to any of your current pages without wrecking your entire layout.

All you need to do, is create a page, put the below code where you want the contact form to show, edit $YourEmail and $YourDepartments variables, save the page with a .php extension and your ready to go!
<?php
// Configuration Start 
$YourEmail "youremail@yourdomain.com";
$YourDepartments = array("Abuse","Domains","General","Other");
// Configuration End 

if($_POST['Submit'] || $Submit)
{
    
// Check all variables sent through POST. Strip 'em!
    
$fEmail = (isset($_POST['email'])) ? (stripslashes(trim($_POST['email']))) : "";
    
$fName = (isset($_POST['name'])) ? (stripslashes(trim($_POST['name']))) : "";
    
$fMessage = (isset($_POST['message'])) ? strip_tags(trim($_POST['message'])) : "";
    
$fDepartment = (isset($_POST['department'])) ? (stripslashes(trim($_POST['department']))) : NULL;
    
    
// Quick variable checks
    
if(empty($fEmail) || empty($fName) || empty($fMessage) || $fDepartment == NULL)
        echo 
"You forgot to enter some required fields. Please <a href="javascripthistory.go(-1)">go back</a> and try again.";
    elseif(!
eregi('^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+.)*([a-z0-9-]+)(.[a-z]{2,3})?)$'$fEmail))
        echo 
"The e-mail is not valid. Please <a href="javascripthistory.go(-1)">go back</a> and try again.";
    else
    {
        
// Set the message format
        
$fMessage "$fName has contacted the $fDepartment department. The message is below.nn***************n$fMessagen***************nnIP of sender: $_SERVER[REMOTE_ADDR]nE-mail of sender: $fEmail";
        
// Prepare e-mail headers for sending
        
$fHeaders 'From: ' $fName ' <' $fEmail '>' "rn" .
        
'Reply-To: ' $fEmail "rn" .
        
'X-Mailer: PHP/' phpversion();
        
// Attmpt to e-mail
        
$tryEmail mail($YourEmail$fDepartment$fMessage$fHeaders);
        if(
$tryEmail)
        echo 
"The form has been sent and you shall receive a reply shortly.";
        else
        echo 
"We are sorry. The e-mail could not be sent. Please try again later.";
    }
}
else
{
    echo 
'<form name="cf" method="post" action="">
    <table border="0" align="center" cellpadding="5" cellspacing="0">
    <tr>
    <td align="right"><strong>Your Name:</strong></td>
    <td><input name="name" type="text" id="name"></td>
    </tr>
    <tr>
    <td align="right"><strong>Your E-Mail:</strong></td>
    <td><input name="email" type="text" id="email"></td>
    </tr>
    <tr>
    <td align="right"><strong>Department:</strong></td>
    <td><select name="department">'
;
    foreach(
$YourDepartments as $Department)
    {
        echo 
'<option>' $Department '</option>';
    }
    echo 
'</select></td>
    </tr>
    <tr>
    <td align="right" valign="top"><strong>Message:</strong></td>
    <td><textarea name="message" cols="30" rows="6" id="message"></textarea></td>
    </tr>
    </table>
    <p align="center">
    <input type="submit" name="Submit" value="Send">
    <input type="reset" name="Reset" value="Reset">
    </p>
    </form>'
;
}
?>

SOCIAL BOOKMARK - Posted by Steven Sullivan on 10th September, 2006 - 23:17:39 GMT

Comments

There are no comments. Why not be the first to comment?

* Name:
* E-Mail:
Not shown to public
Website:
Emotions:
* Comment:

Up

Down

characters left
* Security Code:
Type this code in the box: 817265
* Required field
© Steven Sullivan 2006 - All Rights Reserved         Video Disclaimer - Valid XHTML & CSS