View Single Post
Old 07-22-2005, 02:08 PM   #2 (permalink)
dotDan
Web Guru
 
Name: Dan
Last Online: Today 12:15 AM
iTrader: (5)
Join Date: Apr 2003
Posts: 208
DNF$: 1,929
Location: Connecticut
Country:


Re: My first lil script...and problems :p

You didn't say exactly what was not working with your script.

Anyways, here's a tutorial I wrote recently about mail forms, it should help (feel free to use it, just don't paste your header on it)
Quote:
Better Contact Forms

What I think never occurs to people is that $_GET and $_POST are arrays. Every time someone shows me a contact form, it has line after line of written-out $_POST variables.

The first part to understand is the foreach function. Foreach loops through an array, and allows a script to access each variable in succession.

Example code:
PHP Code:
    <?php
        
foreach($_POST as $key => $value)
        {
            
$message .= $key.' was set to: '.$value."\n";
        }
    
?>
In the above example, $key and $value are made available in each loop. $_POST['name'] = 'Dan' would technically look like $_POST[$key] = $value. This makes it easy to append the values to our message.

The rest of the script is cake:

PHP Code:
    <?php
        $email 
'myname@example.com';
        
$subject $_POST['subject'];
        foreach(
$_POST as $key => $value)
        {
            
$message .= $key.' was set to: '.$value."\n";
        }
        
mail($email,$subject,'From: AutoMailer <noreply>');
    
?>
A bonus is that this code is reusable, so creating contact forms becomes as easy as copy and paste.
dotDan is online now   Reply With Quote