Friday, June 26, 2009

Php- Table editable dynamic form with edit + selection (select / option) + checkbox.

EditTable.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="it">
<head>
    <title>Editable Table - by Fabio Pintore </title>
    <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
    <meta http-equiv="Content-Language" content="it" />
    <meta name="Robots" content="All" />
    <meta name="Description" content="Editable Table" />
    <meta name="Keywords" content="Tabella Editabile con campi fissi (edit) + selezione (select/option) + checkbox" />
    <meta name="Owner" content="Fabio Pintore (f.pintore@tiscali.it)" />
    <meta name="Author" content="Fabio Pintore (f.pintore@tiscali.it)" /> 
    <meta name="Copyright" content="Fabio Pintore (f.pintore@tiscali.it)" />
    <link rel="stylesheet" href="EditTable.css" />
    <script type="text/javascript" src="EditTable.js"></script>
</head>
<body>
<h1>Editable Table</h1>
<form name="FA">
<table cellpadding="0" cellspacing="0" border="0" class="editable" id="editable">
    <thead>   
        <tr>
            <th width="200px">Nome</th>
            <th width="200px">EMail</th>
            <th width="90px">Sesso</th>
            <th width="30px">Socio</th>
        </tr>
    </thead>
    <tbody>
        <tr>
        <td>Aldo Rossi</td>
        <td>a.rossi@emailserver.it</td>
        <td>Maschio</td>
        <td>Si</td>
        </tr>
       
        <tr>
        <td>Maria Verdi</td>
        <td>m.verdi@emailserver.it</td>
        <td>Femmina</td>
        <td>No</td>
        </tr>
       
        <tr>
        <td>Marco Bianchi</td>
        <td>marcobianchi@unaltroemailserver.it</td>
        <td>Maschio</td>
        <td>Si</td>
        </tr>

    </tbody>
</table>
<br/>
<br/>
<script type="text/javascript">
var elArray = makeArray();
var editable=new table.editable(elArray);
editable.init();   
</script>


    <button type="button" onclick="editable.Insert();" name="Insert" value="INSERISCI">
        <b>Inserisci</b>
    </button>
   
    <button type="reset" onclick="editable.Annulla();">
        <b>Annulla</b>
    </button>
       
    <button type="button" onclick="editable.Apply();" name="Apply" value="APPLY">
        <b>Salva</b>
    </button>

</form>
<br/>
<br/>
<a href="http://www.shooney.com/htm/examples/edittable/EditTable.zip">Download this example (Zip File)</a>
</body>
</html>

EditTable.js
******************************************************************************************************************************************************
//  Author    : Fabio Pintore (f.pintore@tiscali.it)
//  Copyright : Fabio Pintore (f.pintore@tiscali.it)
//  Date      : 18 Giugno 2009
//  Descr     : Editable Table
//              Tabella Editabile con campi fissi (edit) + selezione (select/option) + checkbox
//  Note      : [ IT IS FREEWARE ] Lo script ט liberamente e gratuitamente scaricabile e migliorabile.
//              Mi piacerebbe sapere se vi ט stato di aiuto.         
// *******************************************************************************************************************************************************
function oIElText(nameEl){    this.nameEl=nameEl}
oIElText.prototype.Draw = function(val, w0) { return ('<input class="inp" style="width:'+w0+'px" type="text" value="'+val+'" name="'+this.nameEl+'" />'); }
oIElText.prototype.GetValue = function() { return (eval('document.FA.'+this.nameEl+'.value') ); }

function oIElCheck(nameEl){ this.nameEl=nameEl; }
oIElCheck.prototype.Draw = function(val, w0) {
    var app='';
    if (val=='Si') { app='checked="checked"' }
    return ('<input class="inp" type="checkbox" '+app+' value="'+val+'" name="'+this.nameEl+'" />');
}   
oIElCheck.prototype.GetValue = function() { return ( eval('document.FA.'+this.nameEl+'.checked') ? 'Si':'No'); }
   
function oIElComboOpt(dbcode, dbdescr){    this.dbcode=dbcode;    this.dbdescr=dbdescr;}
function oIElCombo(nameEl, dbopt){this.nameEl=nameEl; this.dbopt=dbopt; }
oIElCombo.prototype.Draw = function(val, w0) {
    var app=''; resHTML='';
    resHTML='<select class="inp" style="width:'+w0+'px" name="'+this.nameEl+'" />';
    var cb=this.dbopt;
    for(var j=1;j<cb.length;j++){
        app='';
        if (cb[j].dbdescr == val) {app=' selected '}
        resHTML+='<option value="'+cb[j].dbcode+'" '+app+' >'+cb[j].dbdescr+'</option>';
    }   
    resHTML+='</select>';
    return (resHTML);
}   
oIElCombo.prototype.GetValue = function() {
    var ret='';
    var app=eval('document.FA.'+this.nameEl+'.value');
    var cb=this.dbopt;
   
    for(var j=1;j<cb.length;j++){
        if (cb[j].dbcode == app) {ret=cb[j].dbdescr;}
    }   
    return (ret);
}

function makeArray(){
    var elArray = new Array();
    var optArray = new Array();
   
    optArray[1] = new oIElComboOpt('M','Maschio');
    optArray[2] = new oIElComboOpt('F','Femmina');

    elArray[0]=new oIElText('dbNome');
    elArray[1]=new oIElText('dbEMail');
    elArray[2]=new oIElCombo('dbSesso', optArray);
    elArray[3]=new oIElCheck('dbSocio');
   
    return (elArray);
}

var table=function(){
   
    function editable(elArray){
        this.t; this.w;
        this.Clik=1; this.savedTX=0;this.savedValue=[];this.savedClassTX='';
        this.elArray=elArray; this.Action='';
    }
   
    editable.prototype.init=function(){
        this.t=document.getElementById('editable'); this.w=this.t.rows[0].cells.length;
        for(var i=1;i<this.t.rows.length;i++){    this.t.rows[i].onclick = new Function('editable.doEdit(this)');    }   
    }
   
    editable.prototype.doEdit=function(tx){
        var resHTML=''; w0=0;
       
        if (this.Clik==1){
            this.Clik=0; this.Action="UPD"; this.savedTX = tx;     this.savedClassTX = tx.className;
           
            tx.className='clik';
            tx.onclick='';
   
            for (var i=0;i<this.w;i++){
                w0 = tx.cells[i].offsetWidth;
                this.savedValue[i]=tx.cells[i].childNodes[0].nodeValue;
                resHTML='';
                resHTML = this.elArray[i].Draw(this.savedValue[i], w0);
                tx.cells[i].innerHTML = resHTML;
            }   
        }else{
            if (this.savedTX != tx) { alert ("devi salvare o annullare !") }
        }   

    }   
   
    editable.prototype.Annulla=function(){
        if (this.Action=="UPD"){
            for (var i=0;i<this.w;i++){ this.savedTX.cells[i].innerHTML=this.savedValue[i]; }
            this.savedTX.className=this.savedClassTX;
            this.savedTX.onclick = new Function('editable.doEdit(this)');
        }else {
            if (this.Action=="INS") {  this.t.deleteRow(-1); }   
        }
        this.Action=""; this.Clik=1;
    }
   
    editable.prototype.Apply=function(){
        // FUTURE :  Validate Field - AjaxRequest - ....
        this.TransactOK();
    }
   
    editable.prototype.Insert=function(){
        var z = Array(); resHTML=''; w0=0;
        if (this.Clik==1){
            this.Clik=0; this.Action="INS";
           
            var x=this.t.insertRow(-1);
            this.savedTX = x; this.savedClassTX=x.className;
            x.className='clik';
           
            for (var i=0;i<this.w;i++){
                z[i]=x.insertCell(i);
                w0 = this.t.rows[0].cells[i].offsetWidth;
                resHTML='';
                resHTML = this.elArray[i].Draw('', w0);
                z[i].innerHTML = resHTML;
            }
           
        }else{ alert ("devi salvare o annullare !"); }
    }
   
    editable.prototype.TransactOK=function(){
        for (var i=0;i<this.savedTX.cells.length;i++){     this.savedTX.cells[i].innerHTML=this.elArray[i].GetValue(); }
        this.Clik=1; this.Action=''; this.savedTX.className=this.savedClassTX;
        this.savedTX.onclick = new Function('editable.doEdit(this)');
    }

    return{editable:editable}
   
}();





EditTable.css

body {font:12px Verdana,Arial}

.editable{border:1px solid #ccc; border-bottom:none}
.editable th {padding:4px 6px 6px; background:#444; color:#fff; text-align:left; color:#ccc}
.editable td {padding:2px 4px 4px; background:#fff; border-bottom:1px solid #ccc}
.editable tr:hover {color:#ff0000;outline-style:solid;}
.editable .clik td {background:#00ff80}

.inp {font:12px Verdana,Arial}

Php - Blacklist IPs - Simple way to blacklist IP's, good for instance when you want to stop certain IP ranges known to be spammers.

?php

function IP_Blacklist($minimum = null, $maximum = null)
{
   
$ip = ip2long($_SERVER['REMOTE_ADDR']);

    if (
is_null($minimum) === false)
    {
       
$minimum = explode('.', $minimum);

        foreach (
$minimum as $key => $value)
        {
           
$minimum[$key] = ($value == '*') ? 0 : $value;
        }

       
$minimum = ip2long(implode('.', $minimum));

        if (
$ip >= $minimum)
        {
            return
false;
        }
    }

    if (
is_null($maximum) === false)
    {
       
$maximum = explode('.', $maximum);

        foreach (
$maximum as $key => $value)
        {
           
$maximum[$key] = ($value == '*') ? 255 : $value;
        }

       
$maximum = ip2long(implode('.', $maximum));

        if (
$ip <= $maximum)
        {
            return
false;
        }
    }

    return
true;
}
?>



Usage $_SERVER['REMOTE_ADDR'] = 195.22.23.24:


 
<?php
IP_Blacklist
('195.22.23.*'); // false, blacklisted
IP_Blacklist('195.0.0.0', '195.255.255.255'); // false, blacklisted
IP_Blacklist('195.22.23.25', '195.22.23.255'); // true, clean

if (IP_Blacklist('195.22.23.*', '195.22.23.*') === false)
{
    die(
'Nice try spammer.');
}
?>

Monday, June 22, 2009

PHP- Google Currency Converter - Convert variable amounts between currencies with a little help from our friend Google.

<?php

function Google_Currency($amount, $from, $to)
{
$matches = array();

if (
preg_match('~<b>.+? = (.+?)</b></h2>~', file_get_contents('http://www.google.com/search?q=' . urlencode(floatval($amount) . ' ' . strtoupper($from) . ' to ' . strtoupper($to))), $matches) > 0)
{
if (
array_key_exists(1, $matches) === true)
{
return
floatval($matches[1]);
}
}

return
false;
}
?>





Usage:

<?php
Google_Currency
(1, 'USD', 'EUR'); // 0.768816791
Google_Currency(1, 'USD', 'GBP'); // 0.686671702
Google_Currency(1, 'EUR', 'USD'); // 1.3007
Google_Currency(1, 'EUR', 'GBP'); // 0.893153883
Google_Currency(1, 'GBP', 'USD'); // 1.4563
Google_Currency(1, 'GBP', 'EUR'); // 1.11962789
?>

Link Submition - Allow your visitors to submit links to the site.

Install Instructions.
---------------------

1) Add your information in the variables.php, which is fully commented to make
it easy for you. You should not have to change the first 2 variables. The other
variables are for the Page Title, Text and links above and below on the page.

2) Upload linklist.php, footer.php, header.php, submit.php, variables.php, index.php,
emails.txt and links.txt in ASCII mode to the directory /linklist. Then, upload
browser.gif to the directory /images in BINARY or Auto mode.

3) CHMOD emails.txt and links.txt 777.

3) Your done, to view your Link List page, go to www.yourdomain.com/links/index.php.
To add a link, go to www.yourdomain.com/links/submit.php.


footer.php

<center>
<br>
<font >
<?php
echo $text3 ?>
<br>
<?php echo $text4 ?><br>
<a href="<?php echo $url2 ?>" target=_blank">
<?php
echo $urltext2 ?>
</a></font> <br>
</center><br>
<div align="center"><a href="submit.php"><font size="3" face="Verdana, Arial, Helvetica, sans-serif">Click
Here To Submit Your Site</font></a></div><br>
</html>


index.php

<?php
include "header.php";
?>
<?php
$data
= file('links.txt');
$data = array_reverse($data);
foreach(
$data as $element) {
$element = trim($element);
$pieces = explode("|", $element);
echo
$pieces[2] . $pieces[1] . "" . $pieces[0] . "";
}
?>
<?php
include "footer.php";
?>



header.php

<?php
require "variables.php";
?>
<html>
<head>
<title><?php echo $title ?> </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body bgcolor="#006699" text="#FFFFFF" link="#FFFFFF" vlink="#FFFF00" alink="#FF0000"><font color="#FFFFFF" size="1" face="verdana">
<br>
<center><font size="4">
<?php echo $text1 ?>
<br>
<?php echo $text2 ?>
<br>
<a href="<?php echo $url1 ?>" target=_blank">
<?php
echo $urltext1 ?>
</a><br></font>
</center><br>

<div align="center"><a href="submit.php"><font size="3" face="Verdana, Arial, Helvetica, sans-serif">Click Here To Submit Your Site</font></a></div><br>


submit.php

<?php
require "variables.php";
?>
<html>
<head>
<title><?php echo $title ?> </title>
</head>
<body bgcolor="#006699" text="#FFFFFF" link="#FFFFFF" vlink="#FFFF00" alink="#FF0000">
<center><font size="4">
<?php
echo $text1 ?>
<br>
<?php echo $text2 ?><br>
<a href="<?php echo $url1 ?>" target=_blank">
<?php
echo $urltext1 ?>
</a><br>
<font color="#000000">Submit you site for an Instant Free Listing</font></font>
</center> <FORM METHOD="POST" ACTION="linklist.php">
<table width="500" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td><div align="right"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Website
Name:</font></strong> </div></td>
<td> <div align="left">
<INPUT TYPE="text" NAME="wsname" SIZE="30">
</div></td>
</tr>
<tr>
<td width="105"><div align="right"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Website
URL:</font></strong> </div></td>
<td width="195"> <div align="left">no http:// just www.&nbsp;
<INPUT TYPE="text" NAME="wsurl" SIZE="24">
</div></td>
</tr>
<tr>
<td><div align="right"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Description:</font></strong></div></td>
<td><textarea name="description" cols="26"></textarea></td>
</tr>
<tr>
<td><div align="right"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Email:</font></strong></div></td>
<td><input type="text" NAME="email"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><div align="center">By Submitting your link you agree to recieve mailings
from us.<br>
<INPUT TYPE="submit" value="Submit!">
</div></div>
</td>
</tr>
</table>
</form>

<center><font size="4">
<?php
echo $text1 ?>
<br>
<?php echo $text2 ?><br>
<a href="<?php echo $url2 ?>" target=_blank">
<?php
echo $urltext2 ?>
</a></font>
</center>
</html>


linklist.php

<?php
require "variables.php";
if (
$wsname == "") {
echo
"You must fill out a site name.";
exit;
}
else
if (
$wsurl == "") {
echo
"You must fill out a site URL.";
exit;
}
else
if (
$description == "") {
echo
"You must put a description.";
exit;
}
else
if (
$email == "") {
echo
"You must enter your email.";
exit;
}
else
$textfile = ("links.txt");
$textfile2 = ("emails.txt");
$fp = fopen($textfile, "a+");
fputs ($fp, "<center><table><tr><td bgcolor=666666 width=500 height=20><font size=2><img src=$imagedir/browser.gif><strong><a href=http://$wsurl target=_blank><font size=4>$wsname</font></a></strong></td></tr><tr><td bgcolor=cccccc width=400><font size=2><font color=000000>$description</font></td></tr></table></center><br><br>\n");
fclose($fp);
$fp = fopen($textfile2, "a+");
fputs ($fp, "$email\n");
fclose($fp);
echo
"<html> <title>$title</title><body bgcolor=006699 text=FFFFFF link=FFFFFF vlink=FFFF00 alink=FF0000><font color=FFFFFF size=3 face=verdana><br><center><br> $text1<br>$text2 <br><a href=\"$url1 \" target=_blank\"> $urltext1</a><br><br>Your site has been successfully added. <a href=$viewpage>Click here</a> to view the Link List page.</center></html>";
?>





variables.php

<?php

// This is the page where you will put your free for fall links on. This is a URL!
$viewpage = "index.php";

// The directory to where you will upload your images. DO NOT END WITH TRAILING SLASH!
$imagedir = "images";

// Website Title
$title = "Title Of Link Page";

// Text 1 for top of pages
$text1 = "Your Text Here";

// Text 2 for top of pages
$text2 = "Second Line of Text";

// Link for Top Of Page
$url1 = "http://www.yahoo.com";

//URL 1 Text
$urltext1 = "Text Of URL";

// Text 1 for bottom of pages
$text3 = "Your Text Here";

// Text 2 for bottom of pages
$text4 = "Second Line of Text";

// Link for Top Of Page
$url2 = "http://www.google.com";

//URL 1 Text
$urltext2 = "Text Of URL";
?>

PHP - Customer feedback or simple emailer - A PHP script that enables your visitors to send you emails.

readme.txt

INSTALLATION AND CONFIGURATION

** One major change in version 3.0. You no longer link to emailer.php. You link to whatever form you want to process.
Now, the action of that form has to direct to emailer.php as shown in the sample form.

1- Edit emailer_form.php (or any other form for that matter) by building the form you desire. See reference below for hidden field options.
2- Be sure the action of the form is aimed at the emailer.php file
3- Build the "Thanks" and/or "Error" page(s) if you choose the custom option
4- Edit the top few variable at the top of emailer.php to suit your needs, the available variables are as follows:

<?php
// recipient configuration - this is the array of recipients for the form, the number in the brackets
// must match the number in the "recipient_group" hidden field explained below
$tomail[0]="";
$cc_tomail[0]="";
$bcc_tomail[0]="";
$tomail[1]="";
$cc_tomail[1]="";
$bcc_tomail[1]="";
$tomail[2]="";
$cc_tomail[2]="";
$bcc_tomail[2]="";
// General Variables
// whether or not to check the referrer, 1 for yes, 0 for no
$check_referrer=1;
// domains allowed to use the emailer, with and without www
$referring_domains="http://domain.com/,http://www.domain.com/";
// Default Error and Success Page Variables
$error_page_title="Error - Missed Fields";
$error_page_text="Please use your browser's back button to return to the form and complete the required fields.";
$thanks_page_title="Message Sent";
$thanks_page_text="Thank you for your inquiry";
?>

HIDDEN FIELD OPTIONS
subject - The subject of the email to be sent
reply_to_field - The name of the field that should be put in the "from" field of the email
required_fields - a comma separated list of fieldname to be validated for content
required_email_fields - a comma delimited list of fields to be validated for valid email address syntax
recipient_group - the number that refers to the number in the brackets of the list of recipients to recieve this email
error_page - the filename (and path if necessary) to a custom error page, if missing or blank default text in variable above will be used
thanks_page - the filename (and path if necessary) to a custom thanks page, if missing or blank default text in variable above will be used
send_copy - whether or not to send a copy of the mail to the sender
copy_subject - subject of sent copy
copy_tomail_field - field of email address to the sender for the sent copy
mail_type - layout of email options are "vert_table" or "horz_table", anything else will result in plain text email
mail_priority - 1 is high, 3 is normal
return_ip - do you want the IP of the sender returned with the email if available? 1 is yes, 0 is no

NOTES:
> To call the form link to the emailer.php file NOT the emailer_form.php!
> DO NOT use spaces in the field names of your form. A good option is to use an underscore ("_") instead.
> When making the form, always include the <?php echo $fieldname; ?> as the value of each field. This will make the field populate with the previously entered information should someone not fill out all required fields and see the default error page.
> the recipients_group hidden field may seem confusing, but it is done this way to prevent spambots from harvesting actual email addresses from hidden fields the way many scripts do



header.php

<?php
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Feedback Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<table style="width:600px;border-style:none;" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top">

emailer_form.php

<?php
?>
<html>
<head>
<title>dB Masters FormMailer 3.0</title>
</head>
<body>
<form id="form" method="post" action="emailer.php">
<p>Your Name<br /><input type="text" name="Name" value="<?php echo $Name; ?>" /></p>
<p>Your Email<br /><input type="text" name="Email" value="<?php echo $Email; ?>" /></p>
<p>Comments and/or Questions<br /><text area name="Comments" rows="5" cols="40"><?php echo $Comments; ?></text area></p>
<p>
<input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Reset" value="Clear Form" />
<input type="hidden" name="subject" value="Subject of Email" />
<input type="hidden" name="reply_to_field" value="Email" />
<input type="hidden" name="required_fields" value="Name,Comments" />
<input type="hidden" name="required_email_fields" value="Email" />
<input type="hidden" name="recipient_group" value="0" />
<input type="hidden" name="error_page" value="" />
<input type="hidden" name="thanks_page" value="" />
<input type="hidden" name="send_copy" value="no" />
<input type="hidden" name="copy_subject" value="Subject of Copy Email" />
<input type="hidden" name="copy_tomail_field" value="Email" />
<input type="hidden" name="mail_type" value="vert_table" />
<input type="hidden" name="mail_priority" value="1" />
<input type="hidden" name="return_ip" value="1" />
</p>
</form>
</body>
</html>

footer.php

<?php
?>
</td>
</tr>
<tr>
<td class="bodysm">
</td>
</tr>
</table>
</body>
</html>


emailer.php

<?php
// recipient configuration
$tomail[0]="you@domain.com";
$cc_tomail[0]="";
$bcc_tomail[0]="";
$tomail[1]="";
$cc_tomail[1]="";
$bcc_tomail[1]="";
$tomail[2]="";
$cc_tomail[2]="";
$bcc_tomail[2]="";
// General Variables
$check_referrer=1;
$referring_domains="http://domain.com/,http://www.domain.com/";
// Default Error and Success Page Variables
$error_page_title="Error - Missed Fields";
$error_page_text="Please use your browser's back button to return to the form and complete the required fields.";
$thanks_page_title="Message Sent";
$thanks_page_text="Thank you for your inquiry";

/////////////////////////////////////////////////////////////////////////
// Don't muck around past this line unless you know what you are doing //
/////////////////////////////////////////////////////////////////////////
ob_start();
$required_fields=$_POST["required_fields"];
$required_email_fields=$_POST["required_email_fields"];
$recipients=$_POST["recipient_group"];
$error_page=$_POST["error_page"];
$thanks_page=$_POST["thanks_page"];
$send_copy=$_POST["send_copy"];
$copy_subject=$_POST["copy_subject"];
$copy_tomail_field=$_POST["copy_tomail_field"];
$mail_type=$_POST["mail_type"];
$mail_priority=$_POST["mail_priority"];
$return_ip=$_POST["return_ip"];
if(
$_POST["Submit"]=="Submit")
{
if(
$check_referrer==1)
{
$ref_check=preg_split('/,/',$referring_domains);
$ref_run=sizeof($ref_check);
$referer=$_SERVER['HTTP_REFERER'];
$domain_chk="no";
for(
$i=0;$i<$ref_run;$i++)
{
$cur_domain=$ref_check[$i];
if(
stristr($referer,$cur_domain)){$domain_chk="yes";}
}
}
else
{
$domain_chk="yes";
}
if(
$domain_chk=="yes")
{
$mail="yes";
$req_check=preg_split('/,/',$required_fields);
$req_run=sizeof($req_check);
$error_message="";
for(
$i=0;$i<$req_run;$i++)
{
$cur_field_name=$req_check[$i];
$cur_field=$_POST[$cur_field_name];
if(
$cur_field=="")
{
$error_message=$error_message."You are missing the ".$req_check[$i]." field<br />";
$mail="no";
}
}
$email_check=preg_split('/,/',$required_email_fields);
$email_run=sizeof($email_check);
for(
$i=0;$i<$email_run;$i++)
{
$cur_email_name=$email_check[$i];
$cur_email=$_POST[$cur_email_name];
if(
$cur_email=="" || !eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$",$cur_email))
{
$error_message=$error_message."You are missing the ".$email_check[$i]." field or the email is not a valid email address.<br />";
$mail="no";
}
}
if(
$mail=="yes")
{
if(
getenv(HTTP_X_FORWARDED_FOR))
{
$user_ip=getenv("HTTP_X_FORWARDED_FOR");}
else
{
$user_ip=getenv("REMOTE_ADDR");}
if(
$mail_type=="vert_table")
{
$message="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">
<html>
<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>
<body>
<table cellpadding=\"2\" cellspacing=\"0\" border=\"0\" width=\"600\">\n"
;
foreach(
$_POST as $key=>$value)
{
$value=stripslashes($value);
$value=preg_replace("/(http:\/\/+.[^\s]+)/i",'<a href="\\1">\\1</a>', $value);
$value=nl2br($value);
if(
$key != "Submit" && $key != "subject" && $key != "required_fields" && $key != "required_email_fields" && $key != "recipient_group" && $key != "error_page" && $key != "thanks_page" && $key != "send_copy" && $key != "copy_subject" && $key != "copy_tomail_field" && $key != "mail_type" && $key != "mail_priority" && $key != "return_ip")
{
$message=$message."<tr>\n<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\"><b>".$key."</b></td>\n<td align=\"left\" valign=\"top\" width=\"100%\">".$value."</td></tr>";
}
}
if(
$return_ip==1)
{
$message=$message."<tr>\n<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\"><b>Sender IP</b></td>\n<td align=\"left\" valign=\"top\" width=\"100%\">".$user_ip."</td></tr>";
}
$message=$message."\n</table></body></html>";
}
else if(
$mail_type=="horz_table")
{
$message="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">
<html>
<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>
<body>
<table cellpadding=\"2\" cellspacing=\"0\" border=\"1\">\n
<tr>"
;
foreach(
$_POST as $key=>$value)
{
if(
$key != "Submit" && $key != "subject" && $key != "required_fields" && $key != "required_email_fields" && $key != "recipient_group" && $key != "error_page" && $key != "thanks_page" && $key != "send_copy" && $key != "copy_subject" && $key != "copy_tomail_field" && $key != "mail_type" && $key != "mail_priority" && $key != "return_ip")
{
$message=$message."\n<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\"><b>".$key."</b></td>";
}
}
if(
$return_ip==1)
{
$message=$message."<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\"><b>Sender IP</b></td>";
}
$message=$message."</tr>\n<tr>\n";
foreach(
$_POST as $key=>$value)
{
$value=stripslashes($value);
$value=preg_replace("/(http:\/\/+.[^\s]+)/i",'<a href="\\1">\\1</a>', $value);
$value=nl2br($value);
if(
$key != "Submit" && $key != "subject" && $key != "required_fields" && $key != "required_email_fields" && $key != "recipient_group" && $key != "error_page" && $key != "thanks_page" && $key != "send_copy" && $key != "copy_subject" && $key != "copy_tomail_field" && $key != "mail_type" && $key != "mail_priority" && $key != "return_ip")
{
$message=$message."\n<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\">".$value."</td>";
}
}
if(
$return_ip==1)
{
$message=$message."<td align=\"left\" valign=\"top\" style=\"white-space:nowrap;\">".$user_ip."</td>";
}
$message=$message."\n</tr>\n</table></body></html>";
}
else
{
$message="Form Results";
foreach(
$_POST as $key=>$value)
{
$value=stripslashes($value);
$value=nl2br($value);
if(
$key != "Submit" && $key != "subject" && $key != "required_fields" && $key != "required_email_fields" && $key != "recipient_group" && $key != "error_page" && $key != "thanks_page" && $key != "send_copy" && $key != "copy_subject" && $key != "copy_tomail_field" && $key != "mail_type" && $key != "mail_priority" && $key != "return_ip")
{
$message=$message."\n".$key.": ".$value;
}
}
if(
$return_ip==1)
{
$message=$message."Sender IP: ".$user_ip;
}
}
$extra="From: ".$_POST[$reply_to_field]."\n";
$extra.="X-Priority: $mail_priority\n";
$cc_tomail=$cc_tomail[$recipients];
$bcc_tomail=$bcc_tomail[$recipients];
if(
$cc_tomail!="")
{
$extra.="Cc: $cc_tomail;\n";
}
if(
$bcc_tomail!="")
{
$extra.="Bcc: $bcc_tomail[$recipients]\n";
}
if(
$mail_type=="horz_table" || $mail_type=="vert_table")
{
$extra.="MIME-Version: 1.0\nContent-type: text/html; charset=iso-8859-1\n";
}
$subject=$_POST["subject"];
$tomail=$tomail[$recipients];
mail ("$tomail", "$subject", "$message", "$extra");
if(
$send_copy=="yes")
{
$copy_extra="From: $Name<$Email>\nX-Priority: $mail_priority\n";
if(
$mail_type=="horz_table" || $mail_type=="vert_table")
{
$copy_extra.="MIME-Version: 1.0\nContent-type: text/html; charset=iso-8859-1\n";
}
$copy_address=$_POST[$copy_tomail_field];
mail ("$copy_address", "$copy_subject", "$message", "$copy_extra");
}
if(
$thanks_page=="")
{
echo
"<p>$thanks_page_title</p>";
echo
"<p>$thanks_page_text</p>";
}
else
{
ob_end_clean();
$redirect="Location: ".$thanks_page;
header($redirect);
}
}
else
{
if(
$error_page=="")
{
echo
"<p>$error_page_title</p>";
echo
$error_message;
echo
"<p>$error_page_text</p>";
}
else
{
ob_end_clean();
$redirect="Location: ".$error_page;
header($redirect);
}
}
}
else
{
echo
"<p>Sorry, mailing request came from an unauthorized domain.</p>";
}
}
else
{
echo
"<p>Error</p>";
echo
"<p>No form data has been sent to the script</p>";
}
ob_end_flush();
?>