Hi,

Tuesday, April 20, 2004, 11:10:24 AM, you wrote:
JWH> Does anyone know of a script that'll receive the results of a form,
JWH> parse the original form and substitute the user supplied data in for the
JWH> form elements and then send an HTML email of the "form"?

JWH> For a static form, this obviously isn't too hard, but it'd be ideal if
JWH> the program was dynamic enough to work with any kind of form.

JWH> Let me know if you've heard of anything. If not... well, I guess it's
JWH> writin' time! ;)

JWH> -- 
JWH> ---John Holmes...

JWH> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

JWH> php|architect: The Magazine for PHP Professionals – www.phparch.com

Here is a class I use with my template system but it is easy to modify
it.

//class
class doFormsClass {
        var $text = '';
        var $vars = array();
        var $emailto = '';
        function doFormsClass(){
                if($this->emailto = req::request('EmailTo',false)){
                        $today = Date("d/m/Y H:i:s");
                        $this->text = "Form submitted on $today\n\n";           
//$text holds the email message
                        $this->vars['vars']['header'] = 'Form submitted on '.$today;
                        $x = 0;
                        while (list($k, $v)=each($_POST)) {             //loop through 
all the variables sent
                                switch($k){                                            
                                                         //and break on keywords 
                                        case("EmailTo"):
                                                $this->vars['vars']['mailto'] = $v;
                                                break;
                                        //these we don't want in the email
                                        case 'Quiet':
                                        case 'PHPSESSID':
                                        case 'Email2':
                                        case 'FormBackground':
                                        case 'FormBottomMessage':
                                        case 'FormTopMessage':
                                        case 'FormSubject':
                                        case 'FormRedirect':
                                        case 'submit':
                                        case 'MAIL':
                                                break;
                                        default:                                       
                                                                 //not a keyword
                                                $k = ereg_replace("_"," ",$k);  //get 
rid of _ and replace with a space
                                                if($v == "BR"){                        
                                         //if BR add a carriage return,used for making 
blank line
                                                        
$this->vars['blocks']['submit'][$x]['ifs']['break'] = ' ';
                                                        $this->text .= "\n";
                                                }else{
                                                        
$this->vars['blocks']['submit'][$x]['vars']['name'] = $k;
                                                        
$this->vars['blocks']['submit'][$x]['vars']['value'] = $v;
                                                        $this->text .= "$k : $v\n";    
                                         //add the variable name and value to email
                                                }
                                                $x++;
                                                break;
                                }
                        }
                }
                if(isset($_POST['FormSubject'])){
                        $subject = $_POST['FormSubject'];
                }else{
                        $subject = "Form submitted $today";
                }
                $this->vars['vars']['subject'] = $subject;
                if(isset($_POST['Email']) || isset($_POST['email'])){
                        if(isset($_POST['Email'])):
                                $tail = "FROM: ".$_POST['Email'];
                        else:
                                $tail = "FROM: ".$_POST['email'];
                        endif;
                }
                else{
                        $tail = "FROM: Unknown";
                }
                mail($_POST['EmailTo'],$subject,$this->text,$tail);             //send 
the email
                if(isset($_POST['Email2'])){
                        mail($_POST['Email2'],$subject,$text,$tail);    //send CC if 
needed
                }
        }
        function getVars(){
                return $this->vars;
        }
}



usage
if($form_submitted){
  $df = new doFormsClass();
  $vars = $df->getVars();
  print_r($vars); // use for the template
}

Sample form

<form method="post" action="<? echo $_SERVER['PHP_SELF']?>">
  <!-- email to receive form -->
  <input type="hidden" name="EmailTo" value="email to get form">
  <!-- subject -->
  <input type="hidden" name="FormSubject" value="Web Form Submitted
  <?php echo date('d/m/Y h:i')?>">
  <!-- normal input box (underscores get changed to spaces in email)-->
  Full Name:&nbsp;<input type="text" name="Full_Name" size="30">
  <!-- add a blank line to email -->
  <input type="hidden" name="break1" value="BR">
  <!-- call this Email and it is used in the reply_to bit -->
  Email:&nbsp;<input type="text" name="Email" size="30">
  <input type="submit" name="submit" value="Submit">
</form>
-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to