You can try this... All four files reside in the same directory. This is NOT being used by us on zencart, so there is NO WARRANTY. You may need to modify the html headers (or remove them) if you strip the BODY code into other pages.
File One - contact.php
PHP Code:
<?php
// ** This simple php script drives an input form included with this package
// ** You can change the FIELD NAMES if you wish - just ensure that whatever name you choose CORRESPONDS
// ** with the input names on "contact.html". The field names must be changed in SECTIONS 1, 2 and 3 below.
// **
// ** You can also ADD fields (see the commented out examples below)
// SECTION ONE
// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = "[email protected]"; //The email address to which you want the data to be sent.
$Subject = "SUBJECT OF EMAIL"; //Enter the desired SUBJECT for this email.
$FirstName = Trim(stripslashes($_POST['FirstName']));
$LastName = Trim(stripslashes($_POST['LastName']));
$Company = Trim(stripslashes($_POST['Company']));
$Country = Trim(stripslashes($_POST['Country']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Website = Trim(stripslashes($_POST['Website']));
$Comments = Trim(stripslashes($_POST['Comments']));
//$NewField = Trim(striplashes($_POST['NewField']));
// SECTION TWO
// validation (These set ALL fields as REQUIRED fields)
// To remove validation for any given field, comment it out - eg:
// if (Trim($EmailFrom)=="") $validationOK=false;
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (Trim($FirstName)=="") $validationOK=false;
if (Trim($LastName)=="") $validationOK=false;
if (Trim($Company)=="") $validationOK=false;
if (Trim($Country)=="") $validationOK=false;
if (Trim($Tel)=="") $validationOK=false;
if (Trim($Website)=="") $validationOK=false;
if (Trim($Comments)=="") $validationOK=false;
//if (Trim($NewField)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
exit;
}
//SECTION THREE
// prepare email body text
$Body = "";
$Body .= "FirstName: ";
$Body .= $FirstName;
$Body .= "\n";
$Body .= "LastName: ";
$Body .= $LastName;
$Body .= "\n";
$Body .= "Company: ";
$Body .= $Company;
$Body .= "\n";
$Body .= "Country: ";
$Body .= $Country;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Website: ";
$Body .= $Website;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\n";
//$Body .= "NewField: ";
//$Body .= $NewField;
//$Body .= "\n";
//SECTION FOUR
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page (or if ERROR, redirect to error page)
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
File Two - contact.html
HTML Code:
<!--This is the html code for the INPUT form that is driven by "contact.php".
Place it between the BODY tags of your html page and put it in the same directory as "contact.php"
Remember, if you de-validate fields in the PHP file, remove the relative asterisks in the text below. -->
<span><h3>Contact Form</h3></span>
<p>Please complete the form and submit it to us.
<form method="POST" action="contact.php">
Fields marked (*) are required
<p>Your Email Address:* <br />
<input type="text" name="EmailFrom" size="45">
<br />First Name:* <br />
<input type="text" name="FirstName" size="45">
<br />Last Name:* <br />
<input type="text" name="LastName" size="45">
<br />Company:* <br />
<input type="text" name="Company" size="45">
<br />Country:* <br />
<input type="text" name="Country" size="45">
<br />Telephone (include area codes):* <br />
<input type="text" name="Tel" size="45">
<br />Website (if you have one):*<br />
<input type="text" name="Website" size="45">
<br />Comments / Questions:*<br />
<textarea name="Comments" rows="4" cols="50"></textarea>
<br /><input type="submit" name="submit" value="Submit">
</form>
<!-- if you ADD a NewField to this form, you need to modify contact.php too -->
File Three - thanks.html
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-GB">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Thank You</title>
</head>
<body>
<h1>Thank You</h1>
<div>
<h2> </h2>
<h2>We have received your message</h2>
<p>We will respond soon.</p>
</div>
</body>
</html>
File Four - error.html
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-GB">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Expires" content="-1" />
<title>Oops - there is an error</title>
</head>
<body>
<h1>Oops! Something's not quite right...</h1>
<div>
<h2> </h2>
<h2>We've encountered an error</h2>
<p>Perhaps you did not enter information into a "required" field, or there was a fault in the submission process.<br /><br />
Please use the "Return to Previous Page" button and complete the form again. If you still experience problems, please contact us by telephone.<br />
</p>
<form>
<div align="center"><center><p><input TYPE="button" VALUE="Return to previous page" onClick="history.go(-1)"> </p>
</center></div>
</form>
</div>
</body>
</html>
Bookmarks