contact form help!
Posted: Sat Jun 21, 2008 2:35 am
Hi,
I am getting a 500 internal server error with this form after I added a "name" field. Can someone please help me out?
Form
I am getting a 500 internal server error with this form after I added a "name" field. Can someone please help me out?
Form
mailform.php<form method="POST" id="captcha_form" name="captcha_form" action="mailform.php" style="border:1px; border-color:#FFFFFF">
<div style="padding-bottom: 0.8em;">To:<br />
<select name="emailaddress" id="emailaddress">
<option value="0" selected>Please select a contact</option>
<option value=1>User1</option>
<option value=2>User2</option>
<option value=3>User3</option>
</select>
</div>
<div style="padding-bottom:0.8em;">Name: <br /><input type="text" name="name" id="name" value="">
</div>
<div style="padding-bottom:1em;">Email: <br /><input type="text" name="email" id="email" value="">
</div>
<div style="padding-bottom:0.8em">Subject: <br />
<input type="text" name="subject" id="subject">
</div>
<div style="padding-bottom: 0.8em">Enter the text contained in the image into the text box: <br />
<img src="captcha.php" /> <br />
<input type="text" name="userpass" value="">
</div>
<div style="padding-bottom:0.8em">
Message: <br />
<textarea name="message" id="message" rows="5" cols="30">
<?php echo "</tex" . "tarea>"; ?> <br />
</div>
<div style="padding-bottom:0.8em;">
<input name="submit" type="submit" value="Submit" />
</div>
</form>
<?php
$dontsendemail = 0;
$possiblespam = FALSE;
$strlenmessage = "";
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];
$subject = $_REQUEST['subject'];
$emailaddress = array();
$emailaddress[1] = "user1@gmail.com";
$emailaddress[2] = "user2@gmail.com";
$emailaddress[3] = "user3@gmail.com";
$contactnameindex = $_REQUEST['emailaddress'];
if ($contactnameindex == 0 || !isset($_REQUEST['emailaddress'])) die ("You did not choose a recipient. Please hit your browser back button and try again.");
else $emailaddress = $emailaddress[$contactnameindex];
function checkcaptcha() {
session_start();
if ($_SESSION["pass"] != $_POST["userpass"]) {
die("Sorry, you failed the CAPTCHA. Note that the CAPTCHA is case-sensitive. Please hit your browser back button and try again.");
return 1;
}
}
function checkemail($field) {
// checks proper syntax
if( !preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $field))
{
die("Improper email address detected. Please hit your browser back button and try again.");
return 1;
}
}
function spamcheck($field) {
if(eregi("to:",$field) || eregi("cc:",$field) || eregi("\r",$field) || eregi("\n",$field) || eregi("%0A",$field)){
$possiblespam = TRUE;
}else $possiblespam = FALSE;
if ($possiblespam) {
die("Possible spam attempt detected. If this is not the case, please edit the content of the contact form and try again.");
return 1;
}
}
function strlencheck($field,$minlength,$whichfieldresponse) {
if (strlen($field) < $minlength){
die($whichfieldresponse);
return 1;
}
}
if ($dontsendemail == 0) $dontsendemail = checkcaptcha($email);
if ($dontsendemail == 0) $dontsendemail = checkemail($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($subject);
if ($dontsendemail == 0) $dontsendemail = strlencheck($email,10,"The email address field is too short. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) $dontsendemail = strlencheck($subject,5,"The subject field is too short. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) $dontsendemail = strlencheck($message,10,"The message field is too short. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) $dontsendemail = strlencheck($emailaddress,8,"You have not selected a recipient of your message. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) $dontsendemail = strlencheck($name,2,"The name field is too short. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) {mail($emailaddress,"Subject: $subject","From: $name",$message,"Email: $email" ); echo "Message sent!";}
?>