Hi,
in php I am a complete newbie. I made form with php captcha and php sending to email. I have a problem:
- Captcha does not work and can not be changed captcha code
- Form can not send on email
- As soon not write captcha code, so noerror message is displayed
Please help in solving the problem.
[php]
<?php $nameErr = $emailErr = $opinionErr = ""; $name = $email = $opinion = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Must enter the Name!"; } else { $name = test_input($_POST["name"]); if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and white space allowed"; } } if (empty($_POST["email"])) { $emailErr = "Must enter the name Email!"; } else { $email = test_input($_POST["email"]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; } } if (empty($_POST["opinion"])) { $opinionErr = "Must enter the name opinion"; } else { $opinion = test_input($_POST["opinion"]); } // Check error messages, if none, then send email... if ($nameErr=="" AND $emailErr=="" AND $opinionErr=="") { $to = "My email address"; $name = $_POST['name']; $from = $_POST['email']; $subject = "Opinion on web page"; $subject2 = "Copy of your form - Opinions on website"; $opinion = $title . " " . $name . " " . "\n\n" . $_POST['comment']; $opinion2 = "Here is a copy - Opinions on website " . $name . "\n\n" . $_POST['comment']; if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "n The captcha code does not match!"; } $headers = "From:" . $from; $headers2 = "From:" . $to; mail($to,$subject,$opinion,$headers); mail($from,$subject2,$opinion2,$headers2); header("Location: thanks.html"); } } function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } function IsInjected($str) { $injections = array('(\n+)', '(\r+)', '(\t+)', '(%0A+)', '(%0D+)', '(%08+)', '(%09+)' ); $inject = join('|', $injections); $inject = "/$inject/i"; if(preg_match($inject,$str)) { return true; } else { return false; } } ?>[/php]
In html I have typed:
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label><br>
<input id="6_letters_code" name="6_letters_code" size='8' type="text" class="code"><br>
<a href='javascript: refreshCaptcha();' style='position:relative;top:-27px;left:100px;'><img src="image/circle.png"></a>
Thank you all for help