Wednesday 08 February 2012

Free Contact Form With CAPTCHA

For those of you that don’t already have CAPTCHA running on your contact forms, or are in need of a free PHP contact form with CAPTCHA that you can easily install on your site, you have come to the right place.

For this contact form I am using reCAPTCHA. The main reason is because I feel it is one of the easier CAPTCHA’s for visitors to use because typing real words is easier than typing random strings of text. Secondly, reCAPTCHA heps to digitize scanned books – read more about it here.

While reCAPTCHA is a simple script that can be freely added to your site, the directions for PHP deployment are not intended for the novice. So, I have put together a free open source contact form script using the reCAPTCHA and made it available here.

Download

  Download the Script

Installation

Step 1

The first thing you will need to is get registered at reCAPTCHA by adding your site here. Once you have added your site you will be given a set of public and private API keys. These will be used in the contact form script to activate the reCAPTCHA service.

Step 2

Download and unzip the script to your computer and open contact.php and contact_form.php in your favorite text editor (or notepad if you don’t have one).

On line 10 of contact.php you will need to insert your public key from reCAPTCHA:

$publickey = “yourpublickeygoeshere“;

On line three of contact_form.php you must add your private key from reCAPTCHA:

$privatekey = “yourprivatekeygoeshere“;

On lines 67 of contact_form.php you must replace the email address with the address you want your form submissions to be sent to and modify the subject line if desired. On line 68 you must specify a redirect URL for completed form submissions. Typically this is a “thank you” page that can be used to track conversions.

mail(“you@email.com“,”New Web Contact“,stripslashes($msg), $mailheaders);
header(“Location: http://www.somesite.com“);

Step 3

Copy the entire contents of your edited contact.php and paste the block of code into your site’s HTML where you want your contact form to appear. Don’t forget this must be a PHP page to work.

Step 4

Upload your newly edited contact page from Step 3, along with the contac_form.php and recaptchalib.php and place all three files in the same directory.

That’s All!

Just visit your new contact forms with reCAPTCHA and send yourself a test message to ensure that everything is working correctly.

If you run into any problems or want to provide additional modifications to this script, please join in the conversation below.

  • Helmi Aditya

    I Have problem when install your form, the comment form didn't send email…

    Thanks…..

  • k1ngk9ng

    I always got the mails in Spam/Junk Mail folder, any solution for that problem?

  • Ghjjg

    jhjghjgh

  • http://pulse.yahoo.com/_2LSGY4IDUW3WJ4GKIEAWGZG7MM paulC

    Zach, not receiving my email, but the redirect is working just fine.

    • Anonymous

      Usually this is a result of the server delivering the mail locally. So let’s say you are using Google Apps or GoDaddy for your email, but the server doesn’t know that, so instead the server attempts to deliver the mail locally.

      • http://pulse.yahoo.com/_2LSGY4IDUW3WJ4GKIEAWGZG7MM paulC

        i tried two different emails to troubleshoot, so how do i tell the server to deliver properly and not locally?

        • Anonymous

          How is your email being handled now? I am assuming your email is served by your hosting company or Google Apps, and that you do not currently login into Web Mail on your server. Is this correct? If so, you will need to access the main catchall email on your hosting server. This is typically done by logging into your domain at something like: yourdomain.com/cpanel or /manager.

          • http://pulse.yahoo.com/_2LSGY4IDUW3WJ4GKIEAWGZG7MM paulC

            yes, a hosting company. i have logged in to my webmail to see if it was in junk, nothing.I just found this out for you. The
            script is setup to send the email from the address of the person who
            submitted the form. This will not work. It needs to be sent from an
            address on one of your domains that has been created in the cPanel. Hope this helps.

          • Anonymous

            Ahhh… Yep that makes sense. That will be dependent on the settings in your Apache build. Glad you found the culprit.

  • http://www.facebook.com/people/David-Horvath/1299036661 David Horvath

    Greetings.  On my web form I received the error
    input error: k: Format of site key was invalid 

    • http://www.facebook.com/people/David-Horvath/1299036661 David Horvath

      Sorry, I figured out what I did.  The public and private key codes get entered twice on the same line of html code.

  • Reynardt Badenhorst

    Arg, still saying ‘Could not open socket’

    No answers on the internet… anywhere!

  • Lee Marchais

    this is great, and I just wanted to say thanks for posting it. I’m having trouble, though.

    Everything is lined up on my site, the codes are all in place, but the form isn’t submitting. It won’t even redirect.

Powered by WordPress | Privacy Policy | Web Design Miami