Results 1 to 7 of 7

Thread: [RESOLVED] Is this php code correct for emailing with a Captcha??

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Resolved [RESOLVED] Is this php code correct for emailing with a Captcha??

    PHP Code:
        <?php

        
    require_once('recaptchalib.php');

        
    $publickey "my_publickey";
        
    $privatekey "my_privatekey";
        
    $resp null;
        
    $error null;
        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) {
                    
    $email $_REQUEST['email'] ;
                    
    $message $_REQUEST['message'] ;
                    
    $company $_REQUEST['company'] ;
                    
    $address $_REQUEST['address'] ;
                    
    $city $_REQUEST['city'] ;
                    
    $state $_REQUEST['state'] ;
                    
    $zip $_REQUEST['zip'] ;
                    
    $phone $_REQUEST['phone'] ;
                    
    $sendsale $_REQUEST['sendsalespacket'] ;
                    
    $keep $_REQUEST['keepmeupdated'] ;
                    if ( 
    ereg"[\r\n]"$name) || ereg("[\r\n]"$email ) ) {
                        
    header"Location: error.htm" );
                    }
                    
    mail("[email protected]""Request Packet"$message"Name: $name\nCompany: $company\nAddress: $address\nCity: $city\nState: $state\nZip Code: $zip\nPhone: $phone\nEmail: $email\nComments: $message\nSend Sales Packet: $sendsale\nKeep Me Informed: $keep") ;
                    
    header"Location: contacts.htm" ) ;            
                
                } else {
                        
    # set the error code so that we can display it
                        
    header"Location: error.htm" ) ;
                        
                }
        }
        echo 
    recaptcha_get_html($publickey$error);
        
    ?>

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Is this php code correct for emailing with a Captcha??

    When you run it, does it email properly?

    Are you receiving an error or what?

    The code there runs through a couple functions which I assume are in recaptchalib.php and then uses the mail function to send an email to "[email protected]"

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Re: Is this php code correct for emailing with a Captcha??

    When you type in the captcha codes correctly or incorrectly it goes to the contacts page.

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Is this php code correct for emailing with a Captcha??

    well, then the recaptcha_check_answer() function is at fault (because that's the function that dictates whether or not to go to contacts.htm), which I assume is included in the include you've omitted. I doubt anyone will be able to help you without it.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Re: Is this php code correct for emailing with a Captcha??

    I have abandoned the recaptcha use. I found a site that shows how to create your own.

    THIS Code does not seem to be working and am wondering what things I should be looking for. I am new to PHP so.......
    Code:
    <?php
    if(isset($_POST['captcha'])){
       if(strtolower($_POST['captcha']) == strtolower($_SESSION['captcha'])){
          echo '<div>Success!</div>';
          
       }
       else{
          echo '<div>Incorrect</div>';
       }
    }
    ?>
    This is residing here on my request information page.

    Code:
    <?php session_start(); ?>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Four Lakes Business Systems - Request Information</title>
        <script src="menuscript.js" language="javascript" type="text/javascript">function TEXTAREA1_onclick() {
    
    }
    
    </script>
        <link rel="stylesheet" type="text/css" href="menustyle.css" media="screen, print" />
    </head>
    <body bgcolor=darkgray>
    <?php
    if(isset($_POST['captcha'])){
       if(strtolower($_POST['captcha']) == strtolower($_SESSION['captcha'])){
          echo '<div>Success!</div>';
          
       }
       else{
          echo '<div>Incorrect</div>';
       }
    }
    ?>
    <form method="post" action="sendmail.php">

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: [RESOLVED] Is this php code correct for emailing with a Captcha??

    like stated in my previous post, you're omitting all of the relevant information needed to help you (eg. the script that you're posting from).

    from what you've given me, I can only conclude that maybe your session variable is not being set correctly. you could also have started your session after already outputting something to the browser -- session_start() can only be used before this has happened.

  7. #7
    Addicted Member Phenix's Avatar
    Join Date
    Sep 2002
    Location
    Near A Cube
    Posts
    228

    Don't give up on reCaptcha

    Your noble endeavor was almost complete.

    Make sure you:
    1) put it in a proper HTML page
    2) include an HTML Form tag
    3) the Form tag uses the POST method
    4) *You DID register for a key right?*
    like so:
    Code:
    <?php 
    	require_once('recaptchalib.php');
    
        $publickey = "my_publickey";
        $privatekey = "my_privatekey";
        $resp = null;
        $error = null;
        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) {
                    $email = $_REQUEST['email'] ;
                    $message = $_REQUEST['message'] ;
                    $company = $_REQUEST['company'] ;
                    $address = $_REQUEST['address'] ;
                    $city = $_REQUEST['city'] ;
                    $state = $_REQUEST['state'] ;
                    $zip = $_REQUEST['zip'] ;
                    $phone = $_REQUEST['phone'] ;
                    $sendsale = $_REQUEST['sendsalespacket'] ;
                    $keep = $_REQUEST['keepmeupdated'] ;
                    if ( ereg( "[\r\n]", $name) || ereg("[\r\n]", $email ) ) {
                        header( "Location: error.htm" );
                    }
                    mail("[email protected]", "Request Packet", $message, "Name: $name\nCompany: $company\nAddress: $address\nCity: $city\nState: $state\nZip Code: $zip\nPhone: $phone\nEmail: $email\nComments: $message\nSend Sales Packet: $sendsale\nKeep Me Informed: $keep") ;
                    header( "Location: contacts.htm" ) ;            
                
                } else {
                        # set the error code so that we can display it
                        header( "Location: error.htm" ) ;
                        
                }
        }
    	
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>VBForums mojo69 Testing...</title>
    </head>
    <body>
    <form action="" method="post">
    <?php
    	echo recaptcha_get_html($publickey, $error);
    ?>
    </form>
    </body>
    </html>
    Normally I split my display page with the public key, and the validate page with the private key outside of the webroot. If your web server is ever misconfigured, it could display your PHP code revealing your keys.

    I actually do not use the recaptcha_get_html call with the $error. You might as well not also since you redirect to your custom error or success pages. If you don't redirect to your error page upon error, then I think reCaptcha will display an error for you if you use the call as you had "recaptcha_get_html($publickey, $error);"

    On your workaround custom method without reCaptcha, you probably did not set your SESSION variable.
    Circa 1995
    Engineer - I think we should put our website address on our paper catalogs.
    Vice President - Don't get too excited about this internet thing.


    I am sorry, but the Oracle was mistaken. You cannot help us.
    -Matrix video game


    I'm doing a (free) operating system (just a hobby, won't be big and professional like gnu) for 386(486) AT clones. ... and it probably never will support anything other than AT-harddisks, as that's all I have :-(.
    -Linus


    Question. Do you know that the character "?" means I'm asking a question? Question. Do you know that spoken inflection also provides the same cue? So please don't say, "Question" before you ask your question. Believe me I'll know.

    That said, I would have said this first if it had to precede what I'm telling you now. Having said that, what I'm telling you now is the same thing I just said about the annoying phrases "That said" and "Having said that".


    Are you threatening me, Master Jedi?
    -Chancellor Palpatine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width