Search:     Advanced search
Browse by category:
Glossary

Form mail script, php.

Views: 1016
Votes: 1

Form method needs to be POST,

Email address is set in the form to prevent email harvesting.

<?
# Page to redirect to (take from field "redirect_to" in your form.)
$redirect_to = $_POST["redirect_to"];
# Email address to send email to
$emailaddress = "info@domain.com";
# Email address mail is sent from.
$emailaddressfrom = "info@domain.com";
# Message Subject
$emailsubject = "info@domain.com- ".date("H:i:s");

//==================
// do not edit below here
//==================

$name = array();
$data = array();
$i=0;
foreach ($_POST as $key => $value) {
$name[$i] = $key;
$data[$i] = $value;
$i++;
}
$brk=0;

// check for method other than POST
if ($_SERVER['REQUEST_METHOD'] != "POST"){
$brk=1;
echo "<script language='javascript'>alert('Unauthorized email send!');";
echo "history.go(-1);</script>";
}

//Check for mail injection by spam bots
$bad_str = array ( "content-type:","mime-version:","multipart/mixed","content-transfer-encoding:"
,"bcc:","cc:","to:"
);

$count = count($bad_str);
for ($k=0; $k<$i; $k++) {
$j=0;

while ($j < $count) {
$datadisp = " ".strtolower($data[$k]);
$bad_strdisp = $bad_str[$j];
if (strpos($datadisp, $bad_strdisp) == true) {
$brk++;
echo $brk;

}


$j++;
}
}
if ($brk > 0) {

echo "<script language='javascript'>alert('Mail Injection Detected!');";
echo "history.go(-1);</script>";
break;
}

//Check for HTTP x 3

for ($k=0; $k<$i; $k++) {
$datadisp = " ".strtolower($data[$k]);

if (strpos($datadisp, "http") == true) {

$brk++;
}

}

if ($brk == 0) {
//send email


# Is the OS Windows, Mac or Linux
if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
$eol="\r\n";
} elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {
$eol="\r";
} else {
$eol="\n";
}

 


// message
$message = "Field Name :: Field Data\r\n";
for ($k=0; $k<$i; $k++) {
$msg .= $name[$k]." :: ".$data[$k]."\r\n";
}
$message .= $msg."";

// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: $emailaddressfrom $eol";
$headers .= "Reply-To: $emailaddressfrom $eol";
$headers .= "Return-Path: $emailaddressfrom $eol";    // these two to set reply address

//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

# Finished
$message .= "--".$eol.$eol; // finish with two eol's for better security. see Injection.
$messagetxt = strip_tags($message);
$message = "$messagetxt \r\n"."$message";
# SEND THE EMAIL
//ini_set(sendmail_from,$domain); // the INI lines are to force the From Address to be used !
if (mail($emailaddress, $emailsubject, $message, $headers)) {
echo "<script language='javascript'>alert('Mail Sent Successfully!');</script>";
}
echo "<script language='javascript'>history.go(-1);</script>";
}
echo $brk;


?>

Others in this Category
document Is it possible to offer unlimited bandwidth/space/transfer?
document What is the difference between UNIX hosting and Windows hosting?
document Method of payment we accept: How can I pay for domain registration and web hosting?
document How do I sign up for a hosting plan or a domain name?
document .htaccess file - What is it used for, how to set php memory, how to setup dynamic urls, how to setup redirects



RSS

Del.icio.us Facebook Technorati Digg Furl
TEL : +27 (0) 21 3000 213

SHARED HOSTING

South African Hosting
Unlimited Web Hosting
Business Level Email
Email Only

RESELLER HOSTING

Unlimited - PHP MySQL
Overselling - PHP MySQL

DEDICATED HOSTING

VPS - Dedicated Root Servers

DOMAIN REGISTRATION

Register a Domain Name

 

 

ABOUT US

Contact Details
About Us
Terms and Conditions
Hosting Affiliate Program

 

Providing superior web hosting services. Tel: +27 (0)21 3000 213
Supported Web Technologies: Amplehosting.co.za a Greycell.co.za company. © 2004
Moving Hosts? Client Support