⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formprocessorpro.php

📁 PHP EMAIL FORM PROCESSING Just use php and mysql Follow the instructions as given in the text fil
💻 PHP
📖 第 1 页 / 共 2 页
字号:
                        $file_name = basename($file["name"]);
                        $t_size = $file["size"];
                        srand(time());
            $rnd = sprintf("%08d", floor(rand(0,100000000)));
                        $FORM[$key."_uploaded"] = $rnd . "_" . $file_name . "_._file";
                        $local_file = $attachments_path . $rnd . "_" . $file_name . "_._file";
                        copy ($file["tmp_name"],$local_file)  or Error('File Access Error',"An error occurred when trying to save attachments ($local_file): $!");
            @unlink($file["tmp_name"]);
                        $f_size = 1024 * $GLOBALS[max_file_size];
                        if($t_size > $f_size && $f_size != 0) {
                                unlink($local_file);
                                Error('File Size Error',"Uploading file is too large. It must to be less than $max_file_size KB.");
                            }
            }
        }
}//ParseForm

function CheckRef()
{
global $HTTP_SERVER_VARS, $Referers;
    if (is_array($Referers) and $HTTP_SERVER_VARS['HTTP_REFERER']) {
        foreach ($Referers as $referer) {
            if ( preg_match("/http.*?:\/\/$referer/i", $HTTP_SERVER_VARS['HTTP_REFERER'])) {
                $valid_referer++;
                break;
            }
        }
    } else {
            $valid_referer++;
    }
    if (!$valid_referer) {
        $terms = split(chr(47),$HTTP_SERVER_VARS['HTTP_REFERER']);
    Error ('Bad Referer', "'".$HTTP_SERVER_VARS['HTTP_REFERER']."' is not authorised to use this script. If you want them to be able to, you should add '".$terms[2]."' to the referer list.");
        }
}//CheckRef

function Error ($title, $msg="")
{
global $HTTP_ENV_VARS, $FORM, $base_path,$error_loop,$missing_values,$bad_emails,$only_digits,$only_dig_and_dolar,$only_words;
    ++$error_loop;
$error=array();
    if ($title === 'evil values') {
$val="";

        if ($missing_values) {
            $msg = "<p>The following field(s) are required to be filled in before successful submission:</p>\n<table border=0><tr><td><ol>\n";
            foreach ($missing_values as $val) { $msg .= "<li>$val\n"; }
            $msg .= "</ol></td></tr></table>\n";
                }
        if ($bad_emails) {
            $msg .= "<p>The following field(s) are required to be filled in with valid email addresses before successful submission:</p>\n<table border=0><tr><td><ol>\n";
            foreach ($bad_emails as $val) { $msg .= "<li>$val\n"; }
            $msg .= "</ol></td></tr></table>\n";
                }
        if ($only_digits) {
            $msg .= "<p>The following field(s) are required to be filled in only with digits (0-9) and decimal point before successful submission:</p>\n<table border=0><tr><td><ol>\n";
            foreach ($only_digits as $val) { $msg .= "<li>$val\n"; }
            $msg .= "</ol></td></tr></table>\n";
        }
        if ($only_dig_and_dolar) {
            $msg .= "<p>The following field(s) are required to be filled in only with digits (0-9) a decimal point, or a dollar sign before successful submission:</p>\n<table border=0><tr><td><ol>\n";
            foreach ($only_dig_and_dolar as $val) { $msg .= "<li>$val\n"; }
            $msg .= "</ol></td></tr></table>\n";
        }
        if ($only_words) {
            $msg .= "<p>The following field(s) are required to be filled in only with word characters (A-Z, 0-9) before successful submission:</p>\n<ol type=\"i\">\n";
            foreach ($only_words as $val) { $msg .= "<li>$val\n"; }
            $msg .= "</ol>\n";
        }
                $title = 'Error - Incorrect Values';
                $msg .= "<p>Please go back and fill in the fields accordingly.</p>\n";
        }
    if ($FORM['_error_url']) {
            Header ("Location: ".$FORM['_error_url']);

    } elseif ($FORM['_error_path'] and $error_loop < 2) {
        $HTTP_ENV_VARS['OUT_TITLE'] = $title;
        $HTTP_ENV_VARS['OUT_MSG']   = $msg;
        $error = ReadFile2('Error Template',$base_path.$FORM['_error_path']);
        $error = ParseText($error);
        BrowserOut($error);
        } else {
        $error = get_data();
        $HTTP_ENV_VARS['OUT_TITLE'] = $title;
        $HTTP_ENV_VARS['OUT_MSG']   = $msg;
        $error = ParseText($error);
        BrowserOut($error);
        }
    exit;
}//Error

function LogFile ($msg, $arr)
{
global $base_path;
    $file =  array_shift($arr);
    $file=trim($file);
//    $file =  preg_replace("/^(\s)/","\.\/\\1",$file);
    $file    =  $base_path . $file;

    $fh = fopen($file, 'a+') or Error('File Access Error',"An error occurred when trying to append to the $msg ($file)");
    flock($fh,LOCK_EX) or Error('File Lock Error',"An error occured when locking the $msg ($file):.");
    foreach ($arr as $a) {fputs($fh,$a);}
    fflush($fh);
    flock($fh,LOCK_UN);
    fclose($fh) or Error('File Close Error',"An error occurred when close the $msg ($file).");

}//LogFile

function ReadFile2 ($msg, $file)
{
    $lines = File($file)  or Error('File Access Error',"An error occurred when opening the $msg ($file): $!.");
    return $lines;

}//ReadFile2

function ParseText($arr)
{
global $HTTP_ENV_VARS, $HTTP_SERVER_VARS, $FORM;
    for( $i=0; $i< count($arr); $i++) {
                if (is_array($FORM)) {
                foreach ($FORM as $key => $value)
                    {
                    $value = stripslashes($value);
                    $arr[$i]=preg_replace("#\[".$key."\]#i", $value, $arr[$i]);
                    }
            }
        foreach ($HTTP_ENV_VARS as $key => $value)
            {$arr[$i]=preg_replace("/\[\%$key\]/i",$value, $arr[$i]);}
        foreach ($HTTP_SERVER_VARS as $key => $value) {
                if (!is_array($value)) {
                        $arr[$i]=preg_replace("/\[\%$key\]/i",$value, $arr[$i]);
                        }
                }

                if (preg_match("/\x7e(\w+)((\[)(\d)(\]))?/",$arr[$i],$match))
                {
                eval (" \$rr = $$match[1]; "); //$match[3]$match[4]$match[5]
                $arr[$i] = preg_replace("/\x7e(\w+)((\[)(\d)(\]))?/e", $rr, $arr[$i]);
                }
// remove blank vars
// FIX 14/08/2003
        if (preg_match("/<script/",$arr[$i])) $script = 1;
        if ($script != 1) {
            $arr[$i] = preg_replace("/\[[^<](.)*?[^>]\]/","",$arr[$i]);
            } else {
            $arr[$i] = preg_replace("/([^A-Za-z0-9\-_])\[[^<](.)*?[^>]\]/","\1",$arr[$i]);
            }
        if (preg_match("/<\/script/",$arr[$i])) $script = 0;
// FIX 14/08/2003
        }
    for( $i=0; $i< count($arr); $i++) {
        while (preg_match("/\[<((.)*?)>\]/",$arr[$i],$am)) {
            $sub = $am[1];
                        if (!preg_match("/^([\d\+\*\/\-%\.,x<>\(\)\s]|round|ifcond)*$/s",$sub)) {
//                                Error("Error in expression", $sub);
                        }
                        eval ("\$sub = $sub;");
            $arr[$i] = preg_replace("/\[\<(.)*?\>\]/s", $sub, $arr[$i]);
         }
    }
    return $arr;

}//ParseText

function ifcond ($cond, $res1, $res2)
{
        if ($cond) {
                return sprintf("%s", $res1);
        } else {
                return sprintf("%s", $res2);
        }

}//ifcond

function get_data()
{
return array(
'<html>
<head>
<title>[%OUT_TITLE]</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="navy" vlink="navy" alink="red" style="font-family: verdana, arial, sans-serif; font-size: 8;">
<center><table border="0" cellpadding="0" cellspacing="0" width="500" style="font-family: verdana, arial, sans-serif; font-size: 12;">
  <tr><td><h2 align="center">[%OUT_TITLE]</h2>
    [%UPDATED]
        <p align="center">[%OUT_MSG]</p>
        <p align="center"></td>
  </tr>
</table>
</center>
</body>
</html>');
}//get_data

function ManagePage()
{
global $HTTP_ENV_VARS;
    $HTTP_ENV_VARS['OUT_TITLE'] = "eMail Form Processor Pro Script Administrative Section";
    $HTTP_ENV_VARS['OUT_MSG']   = "";
        $msg=File("cform.html") or Error('Config Form Open Error',"An error occurred when opening config form (cform.html): $!. Please check paths and file.");
    $msg = ParseText($msg);
    BrowserOut($msg);
}//ManagePage

function SavePage() {
ParseForm();
$mas=0;
$lines = ReadFile2('Configuration File', $GLOBALS['cfg_file']);
$fh= fopen($GLOBALS['cfg_file'],"w") or Error('Config Form Open Error',"An error occurred when opening config file($cfg_file): $!. Please check paths and file permissions (Must be 766).");
flock($fh, LOCK_EX);
foreach ($lines as $line) {
        if (preg_match("/^(Referers)\s*=\s*(.+?)\s*(\x23|$)/",$line,$ma))
                {
                $var_name=$ma[1]; $var_value=$ma[2];
                if ($FORM[$var_name.$mas]) {$line=preg_replace("/$var_value/",$FORM[$var_name.$mas],$line);}
                #print "$var_name === $FORM{$var_name.$mas}<br>";
                $mas++;
                }
        elseif (preg_match("/^(\w+)\s*=\s*(.+?)\s*(\x23|$)/",$line))
                {
                $var_name=$ma[1]; $var_value=$ma[2];
        if ($FORM[$var_name]) {$line=preg_replace("/$var_value/",$FORM[$var_name],$line);}
                }
fputs($fh, $line);
}
fflush($fh);
flock($fh, LOCK_UN);
fclose($fh) or Error('Config Form Close Error','An error occured while closing the file ($cfg_file): $!.');

}//SavePage

function StartPage() {
global $HTTP_ENV_VARS;
        $HTTP_ENV_VARS['OUT_TITLE'] = "Form Mail: eMail Form Processor Pro Script";
        $HTTP_ENV_VARS['OUT_MSG']   = '';
    $msg = get_data();
    $msg = ParseText($msg);
    BrowserOut($msg);
}//StartPage

function isEmailBad($value)
{
return ((preg_match("/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/",$value)) or
                                (!preg_match("/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/",$value)));
}//isEmailBad

class mime_mail {
  var $headers;
  var $multipart;
  var $mime;
  var $html;
  var $parts = array();

function mime_mail($headers="") {
    $this->headers=$headers;
}

function add_html($html="") {
    $this->html.=$html;
}

function build_html($orig_boundary, $mail_format="plain") {
    $this->multipart.="--$orig_boundary\r\n";
    $this->multipart.="Content-Type: text/".$mail_format."; charset=ISO-8859-1\r\n";
    //FIX 15.08.2003
    if ($mail_format === 'html') {
        $this->multipart.="Content-Transfer-Encoding: Quot-Printed\r\n\r\n";
        }
    //FIX 15.08.2003
    $this->multipart.="$this->html\r\n\r\n";
}


function add_attachment($path="", $name = "", $rname="", $c_type="application/octet-stream") {
    if (!file_exists($path.$name)) {
      print "File ".$path.$name." dosn't exist.<br>\n";
      return;
    }
    $fp=fopen($path.$name,"rb");
    if (!$fp) {
      print "File $path.$name coudn't be read.";
      return;
    }
    $file=fread($fp, filesize($path.$name));
    fclose($fp);
    $this->parts[]=array("body"=>$file, "name"=>$rname,"c_type"=>$c_type);
}


function build_part($i) {
    $message_part="";
    $message_part.="Content-Type: ".$this->parts[$i]["c_type"];
    if ($this->parts[$i]["name"]!="")
       $message_part.="; name = \"".$this->parts[$i]["name"]."\"\r\n";
    else
       $message_part.="\n";
    $message_part.="Content-Transfer-Encoding: base64\n";
    $message_part.="Content-Disposition: attachment; filename = \"".
       $this->parts[$i]["name"]."\"\r\n\r\n";
    $message_part.=chunk_split(base64_encode($this->parts[$i]["body"]))."\r\n";
    return $message_part;
}


function build_message($mail_format="plain") {
    $boundary="=_".md5(uniqid(time()));
    $this->headers.="MIME-Version: 1.0\r\n";
    $this->headers.="Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
    $this->multipart="";
    $this->multipart.="This is a MIME encoded message.\r\n\r\n";
    $this->build_html($boundary, $mail_format);
    for ($i=(count($this->parts)-1); $i>=0; $i--)
      $this->multipart.="--$boundary\r\n".$this->build_part($i);
    $this->mime = $this->multipart."--$boundary--\r\n";
}


function send($server, $to, $from, $subject="", $headers="") {
    mail($to,$subject,$this->mime,$this->headers);
  }
}//mime_mail

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -