View Single Post
  #3 (permalink)  
Old 05-30-06, 03:26 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Well, if everybody does... lol

I wrote this a while back

PHP Code:

<?php


$recipient 
'you@domain.com';            // Your email address.
$subject 'Contact form submission';    // Subject form email.
$bgcolor '#FFCC00';                     // Background color for empty fields.

// Message for user when message sent.
$message '<p>Thank you, '$_POST['name'] .'. Your message has been sent!</p>';
$message .= '<p><a href="javascript:history.go(-1);">Click here to return</a></p>';

/* 
    Fields:
    Do not use spaces or special chars. 
    Use underscores instead, they will be replaced with spaces.
*/
$fields = array(
            
"name"
            
"mail"
            
"domains"
            
"FTPs"
            
"database"
            
"email_addresses"
            
"email_lists"
            
"cron_jobs"
            
"IP_addresses"
            
"extra_demands",
                );

################################ DO NOT EDIT BELOW ###################################

if (isset($_POST["Submit"]))
{
    
// Checks for empty fields and prepares error variables for the colored background
    
foreach ($fields as $key)
    {
        if (
trim($_POST[$key]) == '')
        {
            
$error[$key] = 1;
        }
    }
    
    if (!isset(
$error))
    {    
        
// Prepare string
        
$string "--------------------------------------\n";
        
$string .= "Date: "date('Y/m/d H:i:s') ."\n";
        
        
// Prepare string for each submission
        
foreach ($_POST as $submission => $value)
        {
            if (
$value == 'Submit'// Skips the submit button
            
{
                continue;
            }
            
            
$string .= str_replace('_'' 'ucfirst($submission)) .': 'stripslashes($value) ."\n";
        }
        
        
$string .= "--------------------------------------\n";
        
$header 'From: "'$recipient .'" <'$recipient .'>';
        
        
mail($recipient$subject$string$header);
                
        
// Show message to user when message sent
        
die($message);
    }
}

    
// HTML Output start
    
echo '<form action="'basename($PHP_SELF) .'" method="post">' ."\n";
    echo 
'<table cellspacing="2" align="center">' ."\n";

    
// Prints all fields
    
foreach ($fields as $field)
    {
        
// Check if an error is set for this field and set background color if necessary
        
if (isset($error[$field]))
        {
            
$style[$field] = ' style="background-color:'$bgcolor .'"';
        }
        
        echo 
'<tr>'"\n";
        echo 
'<td><input type="text" name="'$field .'" value="'stripslashes($_POST[$field]) .'"'$style[$field]  .'/></td>'"\n";
        echo 
'<td> 'str_replace('_'' 'ucfirst($field)) .'</td>';
        echo 
'</tr>'"\n";
    }
    
    echo 
'<td colspan="2" align="center"><input type="submit" name="Submit" value="Submit" /></td>';
    echo 
'</table>';
    echo 
'</form>';
    
?>
Reply With Quote