Probs with craeting a subscribe form with PHP -
02-20-2008
, 08:53 AM
Here is my page with the form on -
http://willowdragonadventureclub.co.uk/index.htm
The PHP code is attached to this message.
Or does anyone know a real easy, simple way of creating a subsription form?
<?PHP
DEFINE('kOptional', true);
DEFINE('kMandatory', false);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);
function DoStripSlashes($FieldValue)
{
if ( get_magic_quotes_gpc() ) {
if (is_array($FieldValue) ) {
return array_map('DoStripSlashes', $FieldValue);
} else {
return stripslashes($FieldValue);
}
} else {
return $FieldValue;
}
}
#----------
# FilterCChars:
function FilterCChars($TheString)
{
return preg_replace('/[\x00-\x1F]/', '', $TheString);
}
#----------
# Validate: Email
function check_email($email, $optional)
{
if ( (strlen($email) == 0) && ($optional === kOptional) ) {
return true;
} elseif (
eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$",
$email) ) {
return true;
} else {
return false;
}
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ClientIP = $_SERVER['REMOTE_ADDR'];
}
$FTGtextfield = DoStripSlashes( $_REQUEST['textfield'] );
$FTGemail = DoStripSlashes( $_REQUEST['email'] );
$FTGSubmit = DoStripSlashes( $_REQUEST['Submit'] );
# Fields Validations
$ValidationFailed = false;
if (!check_email($FTGemail, kMandatory)) {
$ValidationFailed = true;
}
# Redirect user to the error page
if ($ValidationFailed === true) {
header("Location: http://willowdragonadventureclub.co.uk/whoops.htm");
exit;
}
# Email to Form Owner
$emailSubject = FilterCChars("subscribe");
$emailBody = "textfield : $FTGtextfield\n"
. "email : $FTGemail\n"
. "Submit : $FTGSubmit\n"
. "";
$emailTo = 'Steve <contact (AT) willowdragonadventureclub (DOT) co.uk>';
$emailFrom = FilterCChars("contact (AT) willowdragonadventureclub (DOT) co.uk");
$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: 8bit\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Redirect user to success page
header("Location: http://willowdragonadventureclub.co.uk/thanks.htm");
exit;
?> |