Xariez
Xariez

Reputation: 789

Can't get CAPTCHA's to work?

I have recently looked into using CAPTCHAs since I have a contact form I would like to add it to.

However, each captcha seems to be displaying the same issue, which is that once I have implemented the captcha, the textarea where you are supposed to answer the CAPTCHA on has the PHP code in the textarea itself.

If anyone could guide me through as well as link me to some captchas that could work, that would be greatly appreciated!


Here is what I have so far:

Form:

<div class="contactform">
        <form class="form" action="mail.php" method="POST">

            <div class="namebox">
            <p class="name">
                <label for="name">Name</label>
                <input type="text" name="name" id="name">
            </p>
            </div>

            <div class="emailbox">
            <p class="email">
                <label for="email">Email</label>
                <input type="text" name="email" id="email">
            </p>
            </div>

            <div class="titlebox">
            <p class="title">
                <label for="title">Title</label>
                <input type="text" name="title" id="title">
            </p>
            </div>
            <br>

            <div class="descriptionbox">
            <p class="description">
                <label for="description">Description</label>
                <textarea name="description"> </textarea>
            </p>
            </div>

            <br>

            <p class="submit">
                <input type="submit" value="Submit">
            </p>

        </form>
        </div>

PHP:

<?php 
$name = $_POST['name'];
$title = $_POST['title'];
$email = $_POST['email'];
$description = $_POST['description'];
$formcontent ="From: $name \n Message: $description";
$recipient = "[email protected]";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank you. Your message will be reviewed as soon as possible!";
?>

Upvotes: 0

Views: 157

Answers (2)

Funk Forty Niner
Funk Forty Niner

Reputation: 74216

@Fred-ii- So I do realise this is a beyond late answer, but I felt bad for not coming back here. However, I have sorted it out. While this code in specific is not currently in use, I contacted another friend that has quite a bunch of PHP knowledge, mostly just to check and he said the same thing, that the extensions are whats causing it. Cheers for your answers and replies though! :)

Comment to answer to close the question:

What I think may be happening is, your HTML form, isn't holding the .php extension and that's why you have the "PHP code" showing inside it, rather than being parsed.

  • If your file is .htm or .html, rename it to .php

Upvotes: 1

marc_s
marc_s

Reputation: 455

Do you know how CAPTCHA works?
will let me explain it to you:
CAPTCHAs protection system works by generating a random string, writing it to an image, then storing the string inside of a session or by some other method. This is then checked when the form is submitted.
THIS article is a valuable source,check it out and it will guide you to creating a secure CAPTCHA.

Upvotes: 1

Related Questions