Allow visitors to send email to you via your website. Add the Following HTML Form:
|
1.) Add the following HTML form to your page
|
<FORM action=sparkmail.php method=post>
Your Name: <INPUT name=Name><BR>
Your Email Address: <INPUT name=Email>
<BR>Information:<BR><TEXTAREA name=details></TEXTAREA><BR>
<INPUT type=submit value="Send"> </FORM>
|
|
2.) Add the following to the PHP Script
|
<?php
// PHP Form Mail Copyright 2001 Mark Thompson
// www.spartanweb.co.uk
///////////////////////////////////////////////////////////
// User Variables: - Theses need to be changed
// Sucess Url is the url to send them to on success (must have http://)
$success_url = "http://www.spartanweb.co.uk/scripts/formdone.html";
// Fail Url is the url to send them to if their request fails (must have http://)
$fail_url = "http://www.spartanweb.co.uk/scripts/formfail.html";
// The email address to post the data to.
$email = "PutYourEmailHere@YourServer";
//
$blurb = "Message from www.spartanweb.co.uk";
//
// If you want to make any field compulsory, enter their names in the array below
// i.e. if you have <input name="var1"><input name="var"> which muct be filled in
// $required = array ("var1","var2");
$required = array ("", "", "");
////////////////////////////////////////////////////////
//////////////////////////////////////////////////
// You shouldnt need to modify beyond this line
/////////////////////////////////////////////////
// First Check for required variables
if (count($required)>0)
{
for ($i=0;$i<count($required);$i++)
{
$temp = $required[$i];
if ($temp != "")
{
if (!${$temp})
{
header ("Location: $fail_url");
exit;
}
}
}
}
// Prepare the email message
$message = $blurb."\n";
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS))
{
$message .= "$key => $val\n";
}
$message .= "Senders IP => ".$REMOTE_ADDR;
// Send the email
mail($email, "Message from Check Mail", $message,
"From: $email\nReply-To: $email\nX-Mailer: PHP/" . phpversion());
header ("Location: $success_url");
?>
|
Important:
The Form Mailing Scripts are a major Source of Spam on the Internet. It is absolutely essential that nobody can use your script to send email to addresses they choose. The above script uses a hard coded recipients email address, so that email can only be sent to that addresss. Were the user allowed to enter the email address, or it be passed to the script as a variable, then the server could be used to send out email to anyone an un authorised user wished to.
Please note that all code examples are provided "as is", without any kind of warranty.