Here is the html for the form. Just so you know what to call the textfields and so on. And don't forget to use post as a method for the form and action is form.php which is the name of the php script like in this example.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
<title>Welcome to my website!</title>
</head>
<body bgcolor="#ffffff">
<form action="form.php" method="post" name="Form">
<input type="text" name="name" size="24" border="0">
<br>
<input type="text" name="email" size="24" border="0">
<br>
<textarea name="message" rows="4" cols="40">
</textarea>
<br>
<input type="submit" name="button" border="0">
</form>
</body>
</html>
Below here you will find the code for the php formscript. You need to look for the line $emailTo = '"your name" <your@mail.com>';
and change according. So feel free to fill in your name at "your name" and your e-mail address at <your@mail.com>
That's all you need to change.
<?PHP
error_reporting(7);
function check_email($email, $optional)
{
if ( (strlen($email) == 0) && ($optional === true) ) {
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 = $_POST['name'];
$FTGemail = $_POST['email'];
$FTGmessage = $_POST['message'];
$FTGbutton = $_POST['button'];
if (get_magic_quotes_gpc) {
$FTGname = stripslashes($FTGname);
$FTGemail = stripslashes($FTGemail);
$FTGmessage = stripslashes($FTGmessage);
$FTGbutton = stripslashes($FTGbutton);
}
$validationFailed = false;
if ( (! check_email($FTGemail, false))) {
$validationFailed = true;
}
if ($validationFailed == true) {
header("Location: error.html");
exit;
}
$emailTo = '"your name" <your@mail.com>';
$emailSubject = "Form from your website";
$emailSubject = preg_replace('/[x00-x1F]/', '', $emailSubject);
$emailFrom = "$FTGemail";
$emailFrom = preg_replace('/[x00-x1F]/', '', $emailFrom);
$emailBody = "Name: $FTGname\n"
. "E-mail: $FTGemail\n"
. "Message: $FTGmessage\n"
. "\n"
. "\n"
. "";
$emailHeader = "From: $emailFrom\n"
. "Reply-To: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: quoted-printable\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
header("Location: success.html");
exit;
?>
You will also need to create a page that is called error.html just in case something goes wrong when someone tries to submit the form (they fill in a fake e-mail address or something) and you need to create a success.html page so when someone submits the form and all goes well they end up at the success.html page where you can say something like "thank you for filling in our form" or whatever you think of:-)
If you need any help just ask.
Martin