Jump to content

Beginning PHP & direction, Help me get started with someone's "Contact Form"


pontifex

Recommended Posts

I've inherited a website (www.bonniebakerlaw.com) and have found that the previous web developer had left the contact form in quite a shambles.  As you can see it attempts to use a Captcha to validate users, but does not in fact work!  I can leave the entire form blank (including the captcha) and still get to the "Thank You" page indicating the form was correctly submitted (This does not, in fact, actually generate an email correctly)!

 

So before I delve into "Head First PHP & MySQL" to debug and correct the error, I was wondering if some kind person(s) would be good enough to point me to the relevant sections / documentation highlighting the fundamentals of building this type of form correctly coupled with the use of a Captcha as noted.

 

Some code has been REDACTED to protect the innocent.  I won't post the HTML of the form as it's available from the web site and is a fairly simple HTML construct.

 

Form Code:

<?php

require_once('recaptchalib.php');

// Get a key from https://www.google.com/recaptcha/admin/create
$publickey = "REDACTED PUBLIC KEY";
$privatekey = "REDACTED PRIVATE KEY";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if ($resp->is_valid) {
                echo "You got it!";
        } else {
                # set the error code so that we can display it
                $error = $resp->error;
        }
}
echo recaptcha_get_html($publickey, $error);
?>

 

"Thank You" page Code:

 

<?php

$visitor = $_REQUEST['visitor'] ;
$visitormail = $_REQUEST['visitormail'] ;
$State = $_REQUEST['State:'] ;
$Address = $_REQUEST['StreetAddress'] ;
$City = $_REQUEST['City:'] ;
$Zip = $_REQUEST['Zip:'] ;
$Phone = $_REQUEST['Phone:'] ;
$Fax = $_REQUEST['Fax:'] ;
$Emailed = $_REQUEST['Emailed'] ;
$Phoned = $_REQUEST['Phoned'] ;
$Faxed = $_REQUEST['Faxed'] ;
$Postaled = $_REQUEST['Postaled'] ;
$Description = $_REQUEST['IssueDescription'] ;




if ($Emailed == "y") { 
$req1 = "	Email \n" ; 
}

if ($Phoned == "y") {
$req2 = "	Phone \n";
}
if ($Faxed == "y") {
$req3 = "	Fax \n";
}
if ($Postaled == "y") {
$req4 = "	Postal Mail \n";
}
$req = $req1 . $req2 . $req3 . $req4 ;


$message = "name: $visitor
email: $visitormail 
Address: $Address
City: $City
State: $State
Zip: $Zip
Phone: $Phone
Fax: $Fax
Requested contact by:
$req
Description: $Description
" ;


mail("redacted@somedomain.com", "redacted@somedomain.com: contact page", "$message", "From: $visitormail" ) ;

?>

Link to comment
Share on other sites

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.