Hi,
I'm a PHP newbie, still using pre-written code... and dependent on your brains!!!
Need help adding (2) functions to this PHP form script which works just fine as it stands.
NEED:
1.) To include in the form, this code:
<INPUT type="file" name="UPLOAD_FILE1">
<INPUT type="file" name="UPLOAD_FILE2">
<INPUT type="file" name="UPLOAD_FILE3">
and have the image/doc attached to the form results so I can open the attachment and see the image/doc they attached to the form. Right now, the script only gives me the address of where the image is stored instead of attaching the image to the email results along with the data entered.
2.) To include a function which will protect the email address in my form tag from email harvesters.
Any help in this regard would be soooooo appreciated. I'm almost there! Just a couple of tweaks and it will help me tremendously!
HERE IS THE SCRIPT I"M USING:
<?php /********************************************************************
1.) Get the current Time
2.) Get all variables from Get and Post
3.) Make sure they entered all required fields
4.) Send Email
5.) Print HTML/redirect to proper page
- change this line to $debug = true; if you want to enable debugging*/
$debug = false;
/********************************************************************/
if($debug) {
echo "<pre>";
echo "GET Variables:";
print_r($GET);
echo "POST Variables:";
print_r($POST);
echo "</pre>";
error_reporting(E_ALL);
}
else {
error_reporting(0);
}
/******************************************************************
1.) Get the current Time.
*******************************************************************/
$date=date("l, F dS, Y \a\t H:i:s");
/******************************************************************
2.) Get all variables from Get & Post put them into $fields array
*******************************************************************/
if($SERVER['REQUEST_METHOD']=="GET") {
foreach($GET as $name=>$value) {
$fields[$name]=$value;
}
}
elseif($SERVER['REQUEST_METHOD']=="POST") {
foreach($POST as $name=>$value) {
$fields[$name]=$value;
}
}
else {
error($server,"Unkown method. You must specify method=\"GET\" or method=\"POST\" in order for the mailform script to work.");
}
/******************************************************************
3.) Make sure they entered all required fields
*******************************************************************/
$config=array("recipient","subject","email","realname","redirect","required","env_report","sort","print_config","print_blank_fields","title","return_link_url","return_link_title","missing_fields_redirect","background","bgcolor","text_color","link_color","vlink_color","alink_color");
if(isset($fields['required'])) {
$required=preg_split("/,/",$fields['required']);
}
else {
$required=array();
}
//make sure they at least have the email and receipient fields
array_push($required,'email');
array_push($required,'recipient');
$required = array_unique($required);
$field_keys=array_keys($fields);
$missing="";
foreach($required as $value) {
if(!$fields[$value] && $fields[$value]!="0"){
$missing.="<li>$value</li>";
}
}
//if they have missing fields
if($missing) {
//if they have their own missing fields page, direct them there
if(isset($fields['missing_fields_redirect'])) {
header("Location: ".$fields['missing_fields_redirect']);
exit;
}
else {
error($server,"You have not filled in all of the required fields. The missing fields are:<br> <ul>$missing</ul>");
}
}
//if the email address looks invalid
if(!eregi("([_.0-9a-z-]+@)([0-9a-z][0-9a-z-]+.)+([a-z]{2,3})", $fields['email'])) {
error($server,"Please enter a valid email address.");
}
foreach($config as $value) {
if(preg_match("/\~|`|#|\%|^|\&|*|(|)|+|\=|{|}|[|]|<|>|\;||/",$fields[$value])) {
error($server, "Invalid Charaters detected in $value. You may not use any of these characters<br>
~ ` # $ % ^ & * ( ) + = { } [ ] < > ; | <br>
In the form fields.");
}
}
/******************************************************************
4.) Send Email
*******************************************************************/
//sort fields, if needed
if(isset($fields['sort'])) {
if($fields['sort']=="alphabetic") {
ksort($fields);
}
else {
$fields['sort']=preg_replace('/order:/','',$fields['sort']);
$sort_order=preg_split("/,/",$fields['sort']);
foreach($sort_order as $value) {
$temp[$value]=$fields[$value];
}
$temp_keys=array_keys($temp);
foreach($fields as $name=>$value) {
if(!in_array($value,$temp_keys)) {
$temp[$name]=$value;
}
}
$fields=$temp;
}
} //end of sort routine
//create body of email message
$body="Below is the result of your feedback form on www.$server. It was submitted by\n";
if(isset($fields['realname'])) {
$body.=$fields['realname']." (".$fields['email'].")";
}
else {
$body.=$fields['email'];
}
$body.=" on $date \n";
$body.="---------------------------------------------------------------------------\n";
//don't print config fields:
//unless they have print_config set
if(isset($fields['print_config'])) {
$print_config=preg_split("/,/",$fields['print_config']);
$config=array_diff($config,$print_config);
}
foreach($fields as $name=>$value) {
if(!in_array($name,$config)) {
$body.="$name: $value\n";
}
}
$body.="---------------------------------------------------------------------------\n";
//Print off the env_report if that is set
if(isset($fields['env_report'])) {
$env_fields=preg_split("/,/",$fields['env_report']);
foreach($env_fields as $value) {
if(isset($SERVER[$value])) {
$body.="$value: ".$SERVER[$value]."\n";
}
}
}
//set the subject if one doesn't exist
if(!isset($fields['subject'])) {
$fields['subject']="www.$server Form Submission";
}
//Finally, send the message!
mail($fields['recipient'], $fields['subject'], $body, "From: ".$fields['email']);
if($debug) {
echo "<pre>";
echo "Email being sent:<br>";
print_r($body);
echo "</pre>";
}
/******************************************************************
5.) Print HTML/redirect to proper page
*******************************************************************/
//if they set a redirect page, send user there
if(isset($fields['redirect'])) {
header("Location: ".$fields['redirect']);
}
//Set some default values if they are not set
if(!isset($fields['print_blank_fields'])) {
$fields['print_blank_fields']=1;
}
if(!isset($fields['title'])) {
$fields['title']="Thank You!";
}
if(!isset($fields['bgcolor'])) {
$fields['bgcolor']="#ececec";
}
if(!isset($fields['text_color'])) {
$fields['text_color']="#000000";
}
if(!isset($fields['link_color'])) {
$fields['link_color']="#000000";
}
if(!isset($fields['vlink_color'])) {
$fields['vlink_color']="#000000";
}
if(!isset($fields['alink_color'])) {
$fields['alink_color']="#000000";
}
echo <<<TERMHTML
<html>
<head>
<title>Thank You for contacting $server</title>
</head>
<body bgcolor="$fields[bgcolor]" text="$fields[text_color]" link="$fields[link_color]" vlink="$fields[vlink_color]">
<center>
<table border="1" bordercolor="#000000" width="600" cellpadding="4">
<tr>
<td bgcolor="#FEA096">
<font face="arial" size="4" color="$fields[text_color]"><b><center>Here is what you submitted to $server on $date</center></b></font>
</td>
</tr>
<tr>
<td>
TERMHTML;
foreach($fields as $name=>$value) {
if(!in_array($name,$config) && ($value || $fields['print_blank_fields'])) {
echo "<b>$name:</b> $value<br>";
}
}
if(isset($fields['return_link_url']) && isset($fields['return_link_title'])) {
echo "<ul><li><a href=\"$fields[return_link_url]\" target=\"_top\">$fields[return_link_title]</a></ul>";
}
echo <<<TERMHTML
<font face="arial" size="2"></font></td>
</tr>
</table><br><a href="http://www.$server">Click here to return to our main page</a></b>
</body>
</html>
TERMHTML;
/******************************************************************
Function: Error($server,$value)
purpose: print off the error message in $value, nice and neat
Then exit program.
*******************************************************************/
function error($server, $value) {
echo <<<TERMHTML
<html>
<head><title>$server Mailform Error</title></html>
<body bgcolor="$fields[bgcolor]" text="$fields[text_color]" link="$fields[link_color]" vlink="$fields[vlink_color]">
<center>
<table border="1" bordercolor="#000000" width="600" cellpadding="4">
<tr>
<td bgcolor="#FEA096">
<font face="arial" size="4" color="$fields[text_color]"><b><center>$server Mailform Error</center></b></font>
</td>
</tr>
<tr>
<td><b>$value</b>
</td>
</tr>
</table><br><b>Your IP is $_SERVER[REMOTE_ADDR]</b>
</center>
</body>
</html>
TERMHTML;
exit;
}
?>
Thanks!!!
:rolleyes:
Maria