Jump to content

Recommended Posts

hi

i was wondering if anyone had any idea how i can add code A  to code b below? code a is my captcha code and code b is my contact form code thanks..

 

CODE A CAPTCHA:

<?php
if(isset($_POST["captcha"]))
if($_SESSION["captcha"]==$_POST["captcha"])
{
echo 'CAPTHCA is valid; proceed the message';
}
else
{
echo 'CAPTHCA is not valid; ignore submission';
}
?>

CODE B CONTACT FORM:

<?
$mailto = "[email protected]";
$cc = "";
$bcc = "";
$subject = "Email subject";
$vname = "blah blah";
$email = $_POST['email'];
function validateEmail($email)
{
if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$', $email))
return true;
else
return false;
}
if(strlen($_POST['name']) < 1  || strlen($_POST['message']) < 1 || validateEmail($email) == FALSE)
{
$emailerror = 'Error:';
if(empty($_POST['name']))
{
$emailerror .= '<li>Enter name</li>';
}
if(validateEmail($email) == FALSE)
{
$emailerror .= '<li>Enter valid email</li>';
}
if(empty($_POST['message']))
{
$emailerror .= '<li>Enter message</li>';
}
}
else
{
$emailerror .= "Your email has been sent successfully";
$timestamp = date("F j, Y, g:ia");
$messageproper ="\n\n" .
"Name: " .
ucwords($_POST['name']) .
"\n" .
"Email: " .
ucwords($email) .
"\n" .
"Comments: " .
$_POST['message'] .
"\n" .
"\n\n" ;
$messageproper = trim(stripslashes($messageproper));
mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['e_mail'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['e_mail'].">\nX-Mailer: PHP/" . phpversion() );
}
?>

Link to comment
https://forums.phpfreaks.com/topic/254866-add-captcha-to-contact-form/
Share on other sites

put all the email sending code within the if where "echo 'CAPTHCA is valid; proceed the message';" is.

then change 'echo 'CAPTHCA is not valid; ignore submission';" to a prettier error message for the user to view.

 

Either that or have a look at google's reCAPTCHA

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.