Ahhhhhh, but you see, there IS NO javascript!!
Here is the script itself:
Code: Select all
<?php
/*******************************************
My Form Processor
Adapted from the mailer script by
Gavin Bell, http://www.bellonline.co.uk
*******************************************/
extract($_POST);
$host = $_SERVER[HTTP_HOST ];
$path = pathinfo($_SERVER['PHP_SELF']);
$file_path = $path['dirname'];
/*******************************************
Set all variables
*******************************************/
//Email address form will be sent to
$sendto_email = "outreach@ffgf.org";
// Disable email addresses from the same domain as your email from being sent?
// This will often reduce spam but will not allow anyone to send from anything@yourdomain.
$checkdomain = "yes";
// Language variables
$lang_title = "Send an email";
$lang_notice = "Fill in the form to contact us by email. Required fields are shown in bold.";
$lang_name = "Your name:";
$lang_email = "Your email:";
$lang_phone = "Your phone:";
$lang_subject = "Subject:";
$lang_message = "Comments:";
$lang_checkbox = "Please contact me as soon as possible regarding this matter.";
$lang_confirmation = "Please enter validation code. (Note: it is case sensitive.):";
$lang_submit = "Send email";
// Error messages
$lang_error = "Your comments were not submitted. Please correct the following errors:";
$lang_noemail = "You did not enter your email address.";
$lang_nocode = "You did not enter the validation code.";
$lang_wrongcode = "You entered the validation code incorrectly. Please note that it is case sensitive";
$lang_invalidemail = "The email address that you entered appears to be invalid";
// Success
$lang_sent = "Thank you for your comments.<br />The following message was submitted:";
/*******************************************
Validate the form
In this case, just checking for email and
validation code.
*******************************************/
//check for empty email
if (empty ($senders_email))
{
$error = "1";
$info_error .= $lang_noemail . "<br />";
}
//check for invalid email address
if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $senders_email))
{
$error = "1";
$info_error .= $lang_invalidemail . "<br />";
}
//check to see if security code is entered
if (empty ($security_code))
{
$error = "1";
$info_error .= $lang_nocode . "<br />";
}
//check to make sure code entered correctly
elseif ($security_code != $randomness)
{
$error = "1";
$info_error .= $lang_wrongcode . "<br />";
}
//if errors were found, display them
if ($error == "1")
{
$info_notice = "<span style=\"font-weight: bold;\">" . $lang_error . "</span><br />";
if (empty ($submit))
{
$info_error = "";
$info_notice = $lang_notice;
}
require_once("random.php");
$random_code = random();
$mail_message = stripslashes($mail_message);
//display the form
print "
<form name=\"contact\" method=\"post\" action=\"\">
<p>$info_notice<span class=\"error\">$info_error</span></p>
<fieldset>
<legend>Tell us how to get in touch with you:</legend>
<label for=\"name\">$lang_name</label>
<input type=\"text\" id=\"senders_name\" name=\"senders_name\" accesskey=\"n\" tabindex=\"1\" title=\"your name\" value=\"$senders_name\" /><br />
<label for=\"email\" class=\"required\">$lang_email</label>
<input type=\"text\" id=\"senders_email\" name=\"senders_email\" accesskey=\"e\" tabindex=\"2\" title=\"your email\" value=\"$senders_email\" /><br />
<label for=\"phone\">$lang_phone</label>
<input type=\"text\" id=\"phone\" name=\"phone\" accesskey=\"p\" tabindex=\"3\" title=\"your phone\" value=\"$senders_phone\" /><br />
</fieldset>
<p> </p>
<fieldset>
<legend>Enter your comments in the space provided:</legend>
<label for=\"comments\">$lang_message</label>
<textarea name=\"mail_message\" rows=\"5\" cols=\"23\" id=\"mail_message\" accesskey=\"c\" tabindex=\"4\" title=\"mail_message\">$mail_message</textarea><br />
<input class=\"checkbox\" type=\"checkbox\" name=\"contact_me\" value=\"$contact_me\" id=\"contact_me\" accesskey=\"x\" tabindex=\"5\" title=\"Contact Me\" /> $lang_checkbox
</fieldset>
<p>$lang_confirmation</p>
<input name=\"security_code\" type=\"text\" id=\"security_code\" size=\"5\" />
<strong>$random_code</strong>
<input name=\"randomness\" type=\"hidden\" id=\"randomness\" value=\"$random_code\" />
<input name=\"submit\" type=\"submit\" id=\"submit\" value=\"$lang_submit\" />
</form>";
}
else
{
if ($checkdomain == "yes")
{
$sender_domain = substr($senders_email, (strpos($senders_email, '@')) +1);
$recipient_domain = substr($sendto_email, (strpos($sendto_email, '@')) +1);
if ($sender_domain == $recipient_domain)
{
print "Sorry, you cannot send messages from this domain ($sender_domain)";
exit;
}
}
if(isset($contact_me)){ // Check to see if the checkbox is checked
$contact_me = "$lang_checkbox";
}
else {
$contact_me = " I do not want to be contacted. ";
}
$info_notice = $lang_sent;
$mail_message = stripslashes($mail_message);
$senders_email = preg_replace("/[^a-zA-Z0-9s.@-]/", " ", $senders_email);
$senders_name = preg_replace("/[^a-zA-Z0-9s]/", " ", $senders_name);
$mail_subject = "Contact Form Submission";
$headers = "From: $senders_name <$senders_email> \r\n";
$headers .= "X-Mailer: BELLonline.co.uk PHP mailer \r\n";
$mail_contents = "$lang_name $senders_name\n"
. "\n"
. "$lang_email $senders_email\n"
. "\n"
. "$lang_message\n"
. "$mail_message\n"
. "\n"
. "$contact_me\n";
mail($sendto_email, $mail_subject, $mail_contents, $headers);
print "
<p>$info_notice</p>
<p><em>$lang_name</em> $senders_name</p>
<p><em>$lang_email</em> $senders_email</p>
<p><em>$lang_subject</em> $mail_subject</p>
<p><em>$lang_message</em><br /> $mail_message</p>
<p>$contact_me</p>
";
}
?>
And here is the neat little function that does the random string:
Code: Select all
<?php
function Random()
{
$chars = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjklmnopqrstuvwxyz";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 4)
{
$num = rand() % 32;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
?>
Nifty, eh? I was tearing out what few grey hairs I have left trying to find something that could do what I wanted and, better still, could actually understand... sort of.

My head hurts now

, but I've learned a lot with this little exercise!