Hey everyone, so my work wants me to update their website with a email contact form, i foolishly agreed not realising what i was getting myself into, i didn't know how complicated php is (i am an artist, not a coder :icon_redface: ), it's taken me about a week and a half so far to get to this point, i've read a few books, checked out some tutorials online and cobbled together a rough version on my own site.
I'm quite proud that i've made it so far but now i am stuck, i wanted to include a captcha so as to help keep out spam but it just doesn't work, so long as you enter an email into the email field you can submit the form and it'll end up in my inbox, this is frustrating and i really don't know what to do at this point. Can anyone here look at this and see what mistake(s) i've made?
Here is the one i've put up onto my own site if you're interested:
http://www.bboykrillin.com/contact.php
Here is the code on the contact.php page:
<?php
if ($_POST["email"]<>'') {
$ToEmail = 'email@website.com';
$EmailSubject = 'Contact about... ';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
<p>Your message was sent</p>
<?php
} else {
?>
<form action="contact.php" method="post">
<p>Your name:</p>
<input name="name" type="text" id="name" size="32"><br />
<p>Email address:</p>
<input name="email" type="text" id="email" size="32"><br />
<p>Comment:</p>
<textarea name="comment" cols="45" rows="15" id="comment" class="bodytext"></textarea>
<?php
// call the lib..
require_once('recaptchalib.php');
// Get a key from http://recaptcha.net/api/getkey
$publickey = "xXxXxXxXxXxXxXxXx";
$privatekey = "xXxXxXxXxXxXxXxXx";
# was there a reCAPTCHA response?
if ($_POST["submit"]) {
$response = recaptcha_check_answer($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($response->is_valid) {
echo "Yes, that was correct!";
} else {
# set the error code so that we can display it
echo "Eh, That wasn't right. Try Again.";
}
}
?>
<form action="contact.php" method="post">
<?php echo recaptcha_get_html($publickey, $error); ?>
<input style="width: 317px" type="submit" value="submit" name="submit"/>
</form>
<?php
};
?>
And here is the code for the verify.php page:
<?php
require_once('recaptchalib.php');
$privatekey = "xXxXxXxXxXxXxXxXx";
$response = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
?>
I also used the recaptchalib.php code downloaded from www.google.com/recaptcha which i have not modified at all, and the tutorial that gave me the most infomation is at: http://vidiame.com/php/how-to-implement-recaptcha-with-your-php-project (don't know if that's any good to you guys, just trying to give as much info as possible!)
Thanks for taking a look, i hope someone here can see what it is i am missing, i am stumped, the problems with being an artist and not a coder i guess :confused: