Hi,

Monday, September 22, 2003, 11:34:25 AM, you wrote:
JTJ> Not that formmail.pl was the most secure idea, but it could take any
JTJ> variable off any form and mail the contents to a vriable on that form. Does
JTJ> anyone know of such a critter in existence for PHP, a script that will read
JTJ> in all variable on any form and email them. Something already created? Any
JTJ> use of formmail.pl these days would need updating to protect it from
JTJ> spamming. Anything available?

JTJ> --
JTJ> John Taylor-Johnston
JTJ> -----------------------------------------------------------------------------
JTJ> "If it's not open-source, it's Murphy's Law."

JTJ>   ' ' '   Collège de Sherbrooke:
JTJ>  ô¿ô   http://www.collegesherbrooke.qc.ca/languesmodernes/
JTJ>    -     Université de Sherbrooke:
JTJ>           http://compcanlit.ca/
JTJ>           819-569-2064


Here is a class I use to get you started

<?
class doFormsClass {
        var $text = '';
        var $vars = array();
        var $emailto = '';
        function doFormsClass(){
                if(!empty($_POST['EmailTo'])){
                        $this->emailto = $_POST['EmailTo'];
                        $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;
                                        case 'Quiet':
                                        case 'PHPSESSID':
                                        case 'Email2':
                                        case 'FormBackground':
                                        case 'FormBottomMessage':
                                        case 'FormTopMessage':
                                        case 'FormSubject':
                                        case 'FormRedirect':
                                        case 'submit':
                                        case 'MAIL':
                                                break; //drop all of these
                                        default: //otherwise 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]['dropif']['break'] = '&nbsp;';
                                                        $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;
        }
}


The form would start like this
<?
if(isset($_POST['EmailTo'])){
  $df = new doforms(){ //will send the form off by mail
  //display form answers/thankyou message here
}else{
?>
  <form action="<?echo $_SERVER['PHP_SELF']?>" method="post">
  <input type="hidden" name="EmailTo" value="email adress of who gets the form">
  <input type="hidden" name="FormSubject" value="Test form">
  .
  real form inputs here
  .
  </form>
<?}?>

If you are getting an email address for replying to call it name="Email" and the
replyto gets filled in properly.
-- 
regards,
Tom

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

Reply via email to