Jazajay
Active Member
Right well lets add the email validation to it as well, missed that so change this ~
if(!empty($_POST["email"])){
$email = $_POST["email"];
}else{
to~
if(!empty($_POST["email"])){
$email_check = preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST["email"]);
if($email_check!==0){
$email=$_POST["email"];
}else{
$err=$err."Your email address appears to be wrong,<br />";
}
}else{
Right now captcha's I don't tend to use them as they can be beaten, in fact I am unaware of 1 that can't. But lets try this~
require_once('recaptchalib.php');
$privatekey = "your private key";
$resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Please Go back and try it again or we can not send your message." .
"(reCAPTCHA said: " . $resp->error . ")");
}else{
So the whole thing should now look like this ~
<?php
if(isset($_POST['name']))
{
require_once('recaptchalib.php');
$privatekey = "your private key";
$resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Please Go back and try it again or we can not send your message." .
"(reCAPTCHA said: " . $resp->error . ")");
}else{
$count=0;
$err="Please fix the errors below to be able to contact me: <br />";
if(!empty($_POST["name"])){
$from = $_POST["name"];
}else{
$count++;
$err.="Please enter your name<br />";
} if(!empty($_POST["email"])){
$email_check = preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST["email"]);
if($email_check!==0){
$email=$_POST["email"];
}else{
$err.="Your email address appears to be wrong,<br />";
}
}else{
$count++;
$err.="You need to enter an email address so I can contact you<br />";
} if(!empty($_POST['mess'])){
$content = "This message is from $from whose email address is $email.\r\n-----------\r\n ";
$content = $content . $_POST["mess"];
$content = wordwrap($content, 70);
}else{
$count++;
$err.="Your message was blank";
}
if($count==0){
mail('[email protected]', 'website inquiry', $content)?>
<h2>Success</h2>
<p>
Your message has been sent, and I will reply within 48hrs. Thank you.";
</p>
<?php }else{?>
<h2><?php if($count>1){echo $count;?> errors <?php }else{?>1 error <?php }?>occured</h2>
<p>
<?php echo $err;?>
</p>
<form method="post" action="">
<p><label for="n">Name: </label></p>
<p>
<input type="text" name="name" id="n"<?php if(!empty($_POST["name"])){?> value="<?php echo $_POST['name'];?>"<?php }?> />
</p>
<p><label for="e">Email: </label></p>
<p>
<input type="text" name="email" id="e"<?php if(!empty($_POST["email"])){?> value="<?php echo $_POST['email'];?>"<?php }?> />
</p>
<p><label for="m">Message: </label></p>
<p>
<textarea name="mess" cols="50" rows="20" id="m"><?php if(!empty($_POST["mess"])){?><?php echo $_POST['mess'];}?></textarea>
</p>
<p><?php require_once('recaptchalib.php');
$publickey = "...";
echo recaptcha_get_html($publickey);
?></p>
<p><button type="submit">Contact me</button></p>
</form>
<?php }
}
}else{
?>
<form method="post" action="">
<p><label for="n">Name: </label></p>
<p>
<input type="text" name="name" id="n" />
</p>
<p><label for="e">Email: </label></p>
<p>
<input type="text" name="email" id="e" />
</p>
<p><label for="m">Message: </label></p>
<p>
<textarea name="mess" cols="50" rows="20" id="m"></textarea>
</p>
<p><?php require_once('recaptchalib.php');
$publickey = "...";
echo recaptcha_get_html($publickey);
?></p>
<p><button type="submit">Contact me</button></p>
</form>
<?php }?>
Yeah your totally right MCB, I've amended the above script, I had an issue with my CMS yesterday and i just thought ahhhhh so changed it like that but you are totally right.
Right check that now it should be fine, any errors let me know.
Jaz
if(!empty($_POST["email"])){
$email = $_POST["email"];
}else{
to~
if(!empty($_POST["email"])){
$email_check = preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST["email"]);
if($email_check!==0){
$email=$_POST["email"];
}else{
$err=$err."Your email address appears to be wrong,<br />";
}
}else{
Right now captcha's I don't tend to use them as they can be beaten, in fact I am unaware of 1 that can't. But lets try this~
require_once('recaptchalib.php');
$privatekey = "your private key";
$resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Please Go back and try it again or we can not send your message." .
"(reCAPTCHA said: " . $resp->error . ")");
}else{
So the whole thing should now look like this ~
<?php
if(isset($_POST['name']))
{
require_once('recaptchalib.php');
$privatekey = "your private key";
$resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Please Go back and try it again or we can not send your message." .
"(reCAPTCHA said: " . $resp->error . ")");
}else{
$count=0;
$err="Please fix the errors below to be able to contact me: <br />";
if(!empty($_POST["name"])){
$from = $_POST["name"];
}else{
$count++;
$err.="Please enter your name<br />";
} if(!empty($_POST["email"])){
$email_check = preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST["email"]);
if($email_check!==0){
$email=$_POST["email"];
}else{
$err.="Your email address appears to be wrong,<br />";
}
}else{
$count++;
$err.="You need to enter an email address so I can contact you<br />";
} if(!empty($_POST['mess'])){
$content = "This message is from $from whose email address is $email.\r\n-----------\r\n ";
$content = $content . $_POST["mess"];
$content = wordwrap($content, 70);
}else{
$count++;
$err.="Your message was blank";
}
if($count==0){
mail('[email protected]', 'website inquiry', $content)?>
<h2>Success</h2>
<p>
Your message has been sent, and I will reply within 48hrs. Thank you.";
</p>
<?php }else{?>
<h2><?php if($count>1){echo $count;?> errors <?php }else{?>1 error <?php }?>occured</h2>
<p>
<?php echo $err;?>
</p>
<form method="post" action="">
<p><label for="n">Name: </label></p>
<p>
<input type="text" name="name" id="n"<?php if(!empty($_POST["name"])){?> value="<?php echo $_POST['name'];?>"<?php }?> />
</p>
<p><label for="e">Email: </label></p>
<p>
<input type="text" name="email" id="e"<?php if(!empty($_POST["email"])){?> value="<?php echo $_POST['email'];?>"<?php }?> />
</p>
<p><label for="m">Message: </label></p>
<p>
<textarea name="mess" cols="50" rows="20" id="m"><?php if(!empty($_POST["mess"])){?><?php echo $_POST['mess'];}?></textarea>
</p>
<p><?php require_once('recaptchalib.php');
$publickey = "...";
echo recaptcha_get_html($publickey);
?></p>
<p><button type="submit">Contact me</button></p>
</form>
<?php }
}
}else{
?>
<form method="post" action="">
<p><label for="n">Name: </label></p>
<p>
<input type="text" name="name" id="n" />
</p>
<p><label for="e">Email: </label></p>
<p>
<input type="text" name="email" id="e" />
</p>
<p><label for="m">Message: </label></p>
<p>
<textarea name="mess" cols="50" rows="20" id="m"></textarea>
</p>
<p><?php require_once('recaptchalib.php');
$publickey = "...";
echo recaptcha_get_html($publickey);
?></p>
<p><button type="submit">Contact me</button></p>
</form>
<?php }?>
Yeah your totally right MCB, I've amended the above script, I had an issue with my CMS yesterday and i just thought ahhhhh so changed it like that but you are totally right.
Right check that now it should be fine, any errors let me know.
Jaz