Jump to content

How to add Captcha to PHP form??


reflex84

Recommended Posts

Hi,

 

I really need to add a captcha to this PHP process form?

 

How do I go about doing this?

 

<?php

// Define some constants

define( "RECIPIENT_NAME", "John Smith" );

define( "RECIPIENT_EMAIL", "john@example.com" );

define( "EMAIL_SUBJECT", "Visitor Message" );

// Read the form values

$success = false;

$senderName = isset( $_POST['senderName'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['senderName'] ) : "";

$senderEmail = isset( $_POST['senderEmail'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail'] ) : "";

$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";

// If all values exist, send the email

if ( $senderName && $senderEmail && $message ) {

  $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";

  $headers = "From: " . $senderName . " <" . $senderEmail . ">";

  $success = mail( $recipient, EMAIL_SUBJECT, $message, $headers );

}

// Return an appropriate response to the browser

if ( isset($_GET["ajax"]) ) {

  echo $success ? "success" : "error";

} else {

?>

<html>

  <head>

    <title>Thanks!</title>

  </head>

  <body>

  <?php if ( $success ) echo "<p>Thanks for sending your message! We'll get back to you shortly.</p>" ?>

  <?php if ( !$success ) echo "<p>There was a problem sending your message. Please try again.</p>" ?>

  <p>Click your browser's Back button to return to the page.</p>

  </body>

</html>

<?php

}

?>

 

??

 

Thanks in advance!

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.