PDA

View Full Version : mail form subject


King Evil
02-24-2009, 06:44 AM
i already have a working form, but i would like the sender to be able to type in the subject. don't know how to do this (aside from creating the html text box.)

here's my php:


<?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'];
}

$FTGName = DoStripSlashes( $_REQUEST['Name'] );
$FTGEmail = DoStripSlashes( $_REQUEST['Email'] );
$FTGPhone = DoStripSlashes( $_REQUEST['Phone'] );
$FTGComments = DoStripSlashes( $_REQUEST['Comments'] );


# Fields Validations

$ValidationFailed = false;

if (!check_email($FTGEmail, kMandatory)) {
$ValidationFailed = true;
$FTGEmail_errmsg = 'enter a proper email address!';
$ErrorList .= $FTGEmail_errmsg . '<br/>';
}


# Include message in error page and dump it to the browser

if ($ValidationFailed === true) {

$ErrorPage = '<html><head><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>';

$ErrorPage = str_replace('<!--VALIDATIONERROR-->', $ErrorList, $ErrorPage);
$ErrorPage = str_replace('<!--FIELDVALUE:Name-->', $FTGName, $ErrorPage);
$ErrorPage = str_replace('<!--FIELDVALUE:Email-->', $FTGEmail, $ErrorPage);
$ErrorPage = str_replace('<!--FIELDVALUE:Phone-->', $FTGPhone, $ErrorPage);
$ErrorPage = str_replace('<!--FIELDVALUE:Comments-->', $FTGComments, $ErrorPage);
$ErrorPage = str_replace('<!--ERRORMSG:Email-->', $FTGEmail_errmsg, $ErrorPage);


echo $ErrorPage;
exit;

}
# Email to Form Owner

$emailSubject = FilterCChars("Diesel Energy Stix");

$emailBody = "Name : $FTGName\n"
. "Email : $FTGEmail\n"
. "Phone : $FTGPhone\n"
. "Comments : $FTGComments\n"
. "";
$emailTo = 'xxx <xxx@xxx.com>';

$emailFrom = FilterCChars("$FTGEmail");

$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://www.xxx.com");
exit;
?>

edbr
02-24-2009, 07:21 AM
this line sets your subject
$emailSubject = FilterCChars("Diesel Energy Stix");
in your form make a form field call it subject
ten replace the above line with

$emailSubject =$_POST["subject"];
in your script

King Evil
02-24-2009, 07:45 AM
sweet, worked like a charm. thanks.