Location: PHPKode > scripts > LedFormMail > ledformmail.php
<?php
/////////////////////////////////////////////////////////
//ledformmail.php - v1.0
//By: Jon Coulter - hide@address.com
//http://www.ledscripts.com
//
//This script is freeware. I accept no responsibility 
// for damage it may cause (which should be none).
//
//This script can be freely modify, as long as this 
// copyright is included.
//
//Copyright 2000 Jon Coulter - hide@address.com
//
//Bugs: hide@address.com
//Support: hide@address.com
/////////////////////////////////////////////////////////

//Default e-mail address. This is only used if a 'to' isn't specified in the forum
$adminmail	= 'hide@address.com';

//Set equal to 1 if you want the data to be sorted alphabetically
$sort		= 1;

//This is the delimiter that is used for each $key value in the e-mail. Just play around with it.
$delim		= '--';

//Set equal to 1 if you want to check referring hosts.
$refcheck	= 0;

//These are the allowed refferers. If $refcheck above is not set equal to 1, this wont be checked.
//Separate these fields by a ',' (comma)
$referrers	= array('www.ledscripts.com','ledscripts.com');

	#########################################################
	///////////No need to edit below this line///////////////
	#########################################################

//This will get rid of a $message variable. The data is still stored in the $HTTP_GET/POST_VARS array though
unset($message);

//Check for valid referrer
$referer = getenv('HTTP_REFERER');
//Check to make sure there is a referrer
if(empty($referer)){ 
	return_text("This is not a stand alone script. You must submit data to this via a web forum.");
}

$ref_ok=0;
for($i=0;$i<count($referrers);$i++) {
	if($refcheck!=1){
		$ref_ok=1;
		break;
	}
	if(eregi("^https?:\/\/$referrers[$i]",$referer)) {
		$ref_ok=1;
		
		break;
	}
}

$host = preg_replace("|^https?://([\w\.]+)|","\\1",$referer);
$host = preg_replace("|([\w\.]+)/(.*)?|","\\1",$host);
if($ref_ok != 1) {
	return_text("Referring server is not allowed. You need to add <b>'$host'</b> to your <b>\$referrers</b> array.");
}

//Start of the Mail Message
$message = "This data was submitted via a web form at\n$HTTP_REFERER";
$message .= "\nDate: ".date("m/d/Y, h:i A")."\n----------------------------------------";

//Clean Up the GET method variables
if(!empty($HTTP_GET_VARS)){
	unset($get_data);

	while (list ($key,$value) = each ($HTTP_GET_VARS)) {
		if($key=='redirect' || $key=='to' || $key=='subject') {} else {
			$get_data[$key]=$value;
		}
	}
}

//Clean Up the POST method variables
if(!empty($HTTP_POST_VARS)){
	unset($post_data);

	while (list ($key,$value) = each ($HTTP_POST_VARS)) {
		if($key=='redirect' || $key=='to' || $key=='subject') {} else {
			$post_data[$key]=$value;
		}
	}
}

if($sort == 1) {
    @ksort($get_data);
    @ksort($post_data);
}

//Add GET data to the message
if(!empty($get_data)){
	while (list ($key,$value) = each ($get_data)) {
		$message .= "\n$delim$key:\n$value\n";
	}
}

//Add POST data to the message
if(!empty($post_data)){
	while (list ($key,$value) = each ($post_data)) {
		$message .= "\n$delim$key:\n$value\n";
	}
}

//End of the message
$message .= "\n----------------------------------------\n";
$message .= "LedMailFrom by http://www.ledscripts.com";

// Strip PHP's slashes
if(stripslashes($message) != $message) {
	$message = stripslashes($message);
}

//Check for an email field
if(empty($email)) {
	$email = $adminmail;
}

//Check for a Subject Line
if(empty($subject)) {
	$subject = "WWW Form Submission";
}

//Check for a 'to' field
if(empty($to)) {
	$to = $adminmail;
}

//Check for 'realname' field
if(empty($realname)) {
	$realname = $to;
}

//Add name to $email
$email .= " ($realname)";

//Send the E-mail
mail($to, $subject, $message,"From: $email\nReply-To: $email");

//Redirect
if(empty($redirect)){
	return_text("Thank you for filling out the forum. You can return to the previous page right <a href=\"$HTTP_REFERER\">here</a>.");
} else {
	header("Location: $redirect");
}

function return_text($text) {
  ?>
		  <html>
		  <html>
		  <head>
		  <title>LedFormMail</title>
		  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		  <style TYPE="text/css">
		  <!--
		  A:link, A:visited { text-decoration: none }
		  A:hover { text-decoration: underline; color: ffffff }
		  -->
		  </style>
		  </head>

		  <body bgcolor="#CCCCCC" text="#000000" link="#FFFF33" vlink="#FFFF33" alink="#330099">
		  <table width="600" border="1" cellspacing="0" cellpadding="2" align="center">
			<tr bgcolor="#999999" valign="top"> 
			  <td> 
				<div align="center">
				<font face="Verdana, Arial, Helvetica, sans-serif" size="2">
				<b>LedFromMail v1.0</b>
				</font>
				  <hr>
				  <table width="600" border="0" cellspacing="0" cellpadding="2">
					<tr>
					  <td valign="top"> 
					  <p><font face="Arial, Helvetica, sans-serif" size="2"><center>
					  <script src="http://www.ledscripts.com/cgi-bin/ads/remote_ad.pl"></script><noscript>No Ads</noscript><br>
		  <?php
		   echo $text;
		   echo "<br>Copyright <a href=\"http://www.ledscripts.com\">Ledscripts.com</a>, 2000";
		  ?>
			 </center>
			</font>
			</p>
		   </td>
		  </tr>
		 </table>
		</body>
		</html>
   <?

   exit;
}

?>
Return current item: LedFormMail