Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error check in code

    Hi all,

    I have an HTML form and the PHP that it calls on. I added a Captcha/Securimage to my form to prevent spamming and I am still having problems. I have read through several forums and tried editing my PHP a thousand different ways, but it either gives me a different error every time or it does go through to the thank you message WITHOUT sending the form's info to my inbox like it used to.

    The HTML part is working just fine, it refreshes the image and does what it's supposed to do. The problem is just getting it all to verify that all the form info AND the security code are BOTH correct in order to send the form to my inbox.

    I feel like I am so close with this code, but just cant figure out whats wrong. Please help if you can! Thank you!!

    The current error message I'm getting is:
    Parse error: syntax error, unexpected T_ELSE in /home/content/j/e/w/jewelsmac6/html/formhandler2.php on line 106
    ***If i do delete the ELSE from the code, then I get an error saying an unexpected } occurred, so i do that and get another error, and it goes on and on in a circle like this***

    Here is the part of the code from the HTML form that uses the securimage:
    <tr>
    <td>&nbsp;</td>
    <td><img id="captcha" src="../securimage/securimage_show.php" alt="CAPTCHA Image" />
    <input type="text" name="captcha_code" size="10" maxlength="6" />
    <a href="#" onClick="document.getElementById('captcha').src = '../securimage/securimage_show.php?' + Math.random(); return false">Reload Image</a>
    </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td align="right"><input name="Reset" type="reset" value="Reset"></td>
    <td><p><input type="submit" name="Submit" value="Submit"></p></td>
    </tr>
    </table>

    </form>

    </body>
    </html>


    Here is the PHP the form calls on:
    PHP Code:
    <?php session_start();
    ?>

    <?php
       
    if ($_SERVER['REQUEST_METHOD']=="POST"){

       
    // we'll begin by assigning the To address and message subject
       
    $to="jmacdesigns@gmail.com";
       
    $subject="E-mail with attachment";

       
    // get the sender's name and email address
       // we'll just plug them a variable to be used later
       
    $from stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

       
    // generate a random string to be used as the boundary marker
       
    $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

       
    // now we'll build the message headers
       
    $headers "From: $from\r\n" 
       
    "MIME-Version: 1.0\r\n" .
          
    "Content-Type: multipart/mixed;\r\n" .
          
    " boundary=\"{$mime_boundary}\"";

       
    // here, we'll start the message body. all entries ARE case sensitive!!
       // this is the text that will be displayed
       // in the e-mail
        
    $message $_POST['message'];
        
        
    $YourName $_POST['YourName'];
        
    $BizName $_POST['BizName'];
        
    $address $_POST['address'];
        
    $city $_POST['city'];
        
    $State $_POST['State'];
        
    $zipcode $_POST['zipcode'];
        
    $email $_POST['email'];
        
    $JobType $_POST['JobType'];
        
    $JobDimensions $_POST['JobDimensions'];
        
    $Quantity $_POST['Quantity'];
        
    $PaperWhite $_POST['PaperWhite'];
        
    $PaperOffWhite $_POST['PaperOffWhite'];
        
    $PaperCSWhite $_POST['PaperCSWhite'];
        
    $PaperCSOffWhite $_POST['PaperCSOffWhite'];
        
    $PaperOther $_POST['PaperOther'];
        
    $LaminationYes $_POST['LaminationYes'];
        
    $LaminationNo $_POST['LaminationNo'];
        
    $DateReq $_POST['DateReq'];
        
    $comments $_POST['comments'];
        
        
    $message"Your Name: $YourName\n\nBusiness Name: $BizName\n\nAddress: $Address\n\nCity: $City\n\nState: $State\n\nZip Code: $ZipCode\n\nEmail: $email\n\nJob Type: $JobType\n\nJob Dimensions: $JobDimensions\n\nQuantity: $Quantity\n\nPaper White: $PaperWhite\n\nPaper Off White: $PaperOffWhite\n\nPaper Card Stock White: $PaperCSWhite\n\nPaper Card Stock Off White: $PaperCSOffWhite\n\nPaper Other: $PaperOther\n\nLamination Yes: $LaminationYes\n\nLamination No: $LaminationNo\n\nDate Required: $DateReq\n\nComments: $comments\n\n";

       
    // next, we'll build the invisible portion of the message body
       // note that we insert two dashes in front of the MIME boundary 
       // when we use it
       
    $message "This is a multi-part message in MIME format.\n\n" .
          
    "--{$mime_boundary}\n" .
          
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
          
    "Content-Transfer-Encoding: 7bit\n\n" .
       
    $message "\n\n";
    }
       
    // now we'll process our uploaded files
       
    foreach($_FILES as $userfile){
          
    // store the file information to variables for easier access
          
    $tmp_name $userfile['tmp_name'];
          
    $type $userfile['type'];
          
    $name $userfile['name'];
          
    $size $userfile['size'];

          
    // if the upload succeded, the file will exist
          
    if (file_exists($tmp_name)){

             
    // check to make sure that it is an uploaded file and not a system file
             
    if(is_uploaded_file($tmp_name)){
         
                
    // open the file for a binary read
                
    $file fopen($tmp_name,'rb');
         
                
    // read the file content into a variable
                
    $data fread($file,filesize($tmp_name));

                
    // close the file
                
    fclose($file);
         
                
    // now we encode it and split it into acceptable length lines
                
    $data chunk_split(base64_encode($data));
             }
         
             
    // now we'll insert a boundary to indicate we're starting the attachment
             // we have to specify the content type, file name, and disposition as
             // an attachment, then add the file content.
             // NOTE: we don't set another boundary to indicate that the end of the 
             // file has been reached here. we only want one boundary between each file
             // we'll add the final one after the loop finishes.
             
    $message .= "--{$mime_boundary}\n" .
                
    "Content-Type: {$type};\n" .
                
    " name=\"{$name}\"\n" .
                
    "Content-Disposition: attachment;\n" .
                
    " filename=\"{$fileatt_name}\"\n" .
                
    "Content-Transfer-Encoding: base64\n\n" .
             
    $data "\n\n";
          }
       }
          
    // here's our closing mime boundary that indicates the last of the message
       
    $message.="--{$mime_boundary}--\n";
       
       
    //form is posted
        
    else { //form is posted
      
    include("securimage.php");
      
    $img = new Securimage();
      
    $valid $img->check($_POST['code']);

       
    // now we just send the message
        // formhandler2.php
    if ( sizeof($_POST) > $valid == true) {
     
    // process & validate form

     // if all data is present and "clean", then proceed
     
    if ( mail($to$subject$message$headers) ) {
       
    // mail success!
       
    header("Location: thankyou.html");
     } else {
      
    // mail failure!
      
    header("Location: tryagain.html");
     }
    }

    ?>

  • #2
    New Coder
    Join Date
    Aug 2003
    Location
    Derby, UK
    Posts
    97
    Thanks
    0
    Thanked 14 Times in 14 Posts
    PHP Code:
    if ( sizeof($_POST) > $valid == true) { 
    Not checked the file line bbut I suspect this is the problem line. Hard to be sure what it is supposed to be but maybe

    PHP Code:
    if (( sizeof($_POST) > 1) and ($valid == true)) { 
    at a guess?

    HTH,

    Dai

  • #3
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    no luck...

    Hi and thanks for the suggestion. I tried it your way and I am still getting the same error. How can I correct the code for the securimage stuff? I think its something in there thats not written right...?

    Parse error: syntax error, unexpected T_ELSE in /home/content/j/e/w/jewelsmac6/html/formhandler2.php on line 106

    Line 106 starts like this, underneath "//form is posted":
    else { //form is posted
    include("securimage.php");
    $img = new Securimage();
    $valid = $img->check($_POST['code']);

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    PHP Code:
       
          
    // here's our closing mime boundary that indicates the last of the message 
       
    $message.="--{$mime_boundary}--\n"
        
       
    //form is posted 
        
    else { //form is posted 
      
    include("securimage.php"); 
      
    $img = new Securimage(); 
    You got a little something or other there between you're if and else blocks
    That $message appending has to go somewhere else.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    totally lost!

    I'm sorry, but i don't understand your correction.
    There is nothing in there about the $message or the securimage stuff.
    Where do I move the $message part to? Is the ELSE block with the securimage lines written correctly? Does that stay where it is?
    Sorry!

  • #6
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    yupp, just before that is an ordinary code line, but an else statement requires an if statement immediately before it.

    PHP Code:
    // invalid
    if (condition) {
       
    // some code
    }
    doSomething();
    else {
       
    // some code
    }

    // correct
    if (condition) {
       
    // some code
    }
    else {
       
    // some code

    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #7
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry for not being able to reply last night... my wireless keyboard died, of course, and then I had to leave for the day. I hope you're still out there and can help me...!

    Thanks for explaining the IF and ELSE formatting. I think that makes more sense to me now as to what I was missing. So my question is, since I already have the "checker" in place to either send you to the thankyou.html if valid, or the tryagain.html if invalid, how do I add the additional element of checking to see if the securimage info was entered correctly?

    I tried to do this myself by implementing your correct formatting and also follow the instructions from the original source (http://www.phpcaptcha.org/documentation/quickstart/) and I am getting this error, which I have also gotten before in other attempts:

    Fatal error: Call to a member function check() on a non-object in /home/content/j/e/w/jewelsmac6/html/formhandler2.php on line 108

    Here is the PHP code I just used which gave me that error message (if you need it, my HTML form code that calls on this PHP is in my original post) :
    PHP Code:
    <?php session_start();
    ?>

    <?php
       
    if ($_SERVER['REQUEST_METHOD']=="POST"){

       
    // we'll begin by assigning the To address and message subject
       
    $to="jmacdesigns@gmail.com";
       
    $subject="E-mail with attachment";

       
    // get the sender's name and email address
       // we'll just plug them a variable to be used later
       
    $from stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

       
    // generate a random string to be used as the boundary marker
       
    $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

       
    // now we'll build the message headers
       
    $headers "From: $from\r\n" 
       
    "MIME-Version: 1.0\r\n" .
          
    "Content-Type: multipart/mixed;\r\n" .
          
    " boundary=\"{$mime_boundary}\"";

       
    // here, we'll start the message body. all entries ARE case sensitive!!
       // this is the text that will be displayed
       // in the e-mail
        
    $message $_POST['message'];
        
        
    $YourName $_POST['YourName'];
        
    $BizName $_POST['BizName'];
        
    $address $_POST['address'];
        
    $city $_POST['city'];
        
    $State $_POST['State'];
        
    $zipcode $_POST['zipcode'];
        
    $email $_POST['email'];
        
    $JobType $_POST['JobType'];
        
    $JobDimensions $_POST['JobDimensions'];
        
    $Quantity $_POST['Quantity'];
        
    $PaperWhite $_POST['PaperWhite'];
        
    $PaperOffWhite $_POST['PaperOffWhite'];
        
    $PaperCSWhite $_POST['PaperCSWhite'];
        
    $PaperCSOffWhite $_POST['PaperCSOffWhite'];
        
    $PaperOther $_POST['PaperOther'];
        
    $LaminationYes $_POST['LaminationYes'];
        
    $LaminationNo $_POST['LaminationNo'];
        
    $DateReq $_POST['DateReq'];
        
    $comments $_POST['comments'];
        
        
    $message"Your Name: $YourName\n\nBusiness Name: $BizName\n\nAddress: $Address\n\nCity: $City\n\nState: $State\n\nZip Code: $ZipCode\n\nEmail: $email\n\nJob Type: $JobType\n\nJob Dimensions: $JobDimensions\n\nQuantity: $Quantity\n\nPaper White: $PaperWhite\n\nPaper Off White: $PaperOffWhite\n\nPaper Card Stock White: $PaperCSWhite\n\nPaper Card Stock Off White: $PaperCSOffWhite\n\nPaper Other: $PaperOther\n\nLamination Yes: $LaminationYes\n\nLamination No: $LaminationNo\n\nDate Required: $DateReq\n\nComments: $comments\n\n";

       
    // next, we'll build the invisible portion of the message body
       // note that we insert two dashes in front of the MIME boundary 
       // when we use it
       
    $message "This is a multi-part message in MIME format.\n\n" .
          
    "--{$mime_boundary}\n" .
          
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
          
    "Content-Transfer-Encoding: 7bit\n\n" .
       
    $message "\n\n";
    }
       
    // now we'll process our uploaded files
       
    foreach($_FILES as $userfile){
          
    // store the file information to variables for easier access
          
    $tmp_name $userfile['tmp_name'];
          
    $type $userfile['type'];
          
    $name $userfile['name'];
          
    $size $userfile['size'];

          
    // if the upload succeded, the file will exist
          
    if (file_exists($tmp_name)){

             
    // check to make sure that it is an uploaded file and not a system file
             
    if(is_uploaded_file($tmp_name)){
         
                
    // open the file for a binary read
                
    $file fopen($tmp_name,'rb');
         
                
    // read the file content into a variable
                
    $data fread($file,filesize($tmp_name));

                
    // close the file
                
    fclose($file);
         
                
    // now we encode it and split it into acceptable length lines
                
    $data chunk_split(base64_encode($data));
             }
         
             
    // now we'll insert a boundary to indicate we're starting the attachment
             // we have to specify the content type, file name, and disposition as
             // an attachment, then add the file content.
             // NOTE: we don't set another boundary to indicate that the end of the 
             // file has been reached here. we only want one boundary between each file
             // we'll add the final one after the loop finishes.
             
    $message .= "--{$mime_boundary}\n" .
                
    "Content-Type: {$type};\n" .
                
    " name=\"{$name}\"\n" .
                
    "Content-Disposition: attachment;\n" .
                
    " filename=\"{$fileatt_name}\"\n" .
                
    "Content-Transfer-Encoding: base64\n\n" .
             
    $data "\n\n";
          }
       }
          
    // here's our closing mime boundary that indicates the last of the message
       
    $message.="--{$mime_boundary}--\n";
       
       
    //securimage code at http://www.phpcaptcha.org/documentation/quickstart/
    include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
    $securimage = new Securimage();
    $valid $img->check($_POST['code']);
        
    //Next we will actually check to see if the code was correct.
    if ($securimage->check($_POST['captcha_code']) == false) {
      
    // the code was incorrect
      // handle the error accordingly with your other error checking
    }

       
    // now we just send the message
        // formhandler2.php
     
    if (( sizeof($_POST) > 1) and ($valid == true)) {
     
    // process & validate form

     // if all data is present and "clean", then proceed
     
    if ( mail($to$subject$message$headers) ) {
       
    // mail success!
       
    header("Location: thankyou.html");
     } else {
      
    // mail failure!
      
    header("Location: tryagain.html");
     }
    }

    ?>

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    This one should be a simple fix (but I'm not sure what you want to do with it):
    PHP Code:
    $securimage = new Securimage(); 
    $valid $img->check($_POST['code']); 
    $img is not an object, chances are that second line there should be $valid = $securimage->check($_POST['code']);, but I cannot be 100% certain since I've never used a prebuilt captcha before.

    BTW, this one is more work than you need (though it is technically more accurate, since you're checking for true):
    PHP Code:
    if (( sizeof($_POST) > 1) and ($valid == true)) { 
    The same could be written as
    PHP Code:
    if (sizeof($_POST) > && $valid) { // Or count($_POST) 
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #9
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    and another perspective …

    PHP Code:
    require_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'
    to see if the file was actually loaded. (though I agree with Fou-Lu about the $img.)
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by Dormilich View Post
    and another perspective …

    PHP Code:
    require_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'
    to see if the file was actually loaded. (though I agree with Fou-Lu about the $img.)
    It won't be a problem with the inclusion. If it failed, the require will trigger a fatal error. What is possible is that the file itself is incorrect, but then it would complain about how it cannot find the definition for the class SecurImage when instatiating it rather than when trying to call on the non-object.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #11
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    Quote Originally Posted by Fou-Lu View Post
    It won't be a problem with the inclusion. If it failed, the require will trigger a fatal error.
    exactly, if the fatal error doesn’t come up, you can be sure the file is at least loaded.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #12
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you all for your feedback. I tried your corrections and am getting the same error as before:

    Fatal error: Call to a member function check() on a non-object in /home/content/j/e/w/jewelsmac6/html/formhandler2.php on line 107

    Do you know what this check() thing is that it is asking for?

    PHP Code:
    <?php session_start();
    ?>

    <?php
       
    if ($_SERVER['REQUEST_METHOD']=="POST"){

       
    // we'll begin by assigning the To address and message subject
       
    $to="jmacdesigns@gmail.com";
       
    $subject="E-mail with attachment";

       
    // get the sender's name and email address
       // we'll just plug them a variable to be used later
       
    $from stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

       
    // generate a random string to be used as the boundary marker
       
    $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

       
    // now we'll build the message headers
       
    $headers "From: $from\r\n" 
       
    "MIME-Version: 1.0\r\n" .
          
    "Content-Type: multipart/mixed;\r\n" .
          
    " boundary=\"{$mime_boundary}\"";

       
    // here, we'll start the message body. all entries ARE case sensitive!!
       // this is the text that will be displayed
       // in the e-mail
        
    $message $_POST['message'];
        
        
    $YourName $_POST['YourName'];
        
    $BizName $_POST['BizName'];
        
    $address $_POST['address'];
        
    $city $_POST['city'];
        
    $State $_POST['State'];
        
    $zipcode $_POST['zipcode'];
        
    $email $_POST['email'];
        
    $JobType $_POST['JobType'];
        
    $JobDimensions $_POST['JobDimensions'];
        
    $Quantity $_POST['Quantity'];
        
    $PaperWhite $_POST['PaperWhite'];
        
    $PaperOffWhite $_POST['PaperOffWhite'];
        
    $PaperCSWhite $_POST['PaperCSWhite'];
        
    $PaperCSOffWhite $_POST['PaperCSOffWhite'];
        
    $PaperOther $_POST['PaperOther'];
        
    $LaminationYes $_POST['LaminationYes'];
        
    $LaminationNo $_POST['LaminationNo'];
        
    $DateReq $_POST['DateReq'];
        
    $comments $_POST['comments'];
        
        
    $message"Your Name: $YourName\n\nBusiness Name: $BizName\n\nAddress: $Address\n\nCity: $City\n\nState: $State\n\nZip Code: $ZipCode\n\nEmail: $email\n\nJob Type: $JobType\n\nJob Dimensions: $JobDimensions\n\nQuantity: $Quantity\n\nPaper White: $PaperWhite\n\nPaper Off White: $PaperOffWhite\n\nPaper Card Stock White: $PaperCSWhite\n\nPaper Card Stock Off White: $PaperCSOffWhite\n\nPaper Other: $PaperOther\n\nLamination Yes: $LaminationYes\n\nLamination No: $LaminationNo\n\nDate Required: $DateReq\n\nComments: $comments\n\n";

       
    // next, we'll build the invisible portion of the message body
       // note that we insert two dashes in front of the MIME boundary 
       // when we use it
       
    $message "This is a multi-part message in MIME format.\n\n" .
          
    "--{$mime_boundary}\n" .
          
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
          
    "Content-Transfer-Encoding: 7bit\n\n" .
       
    $message "\n\n";
    }
       
    // now we'll process our uploaded files
       
    foreach($_FILES as $userfile){
          
    // store the file information to variables for easier access
          
    $tmp_name $userfile['tmp_name'];
          
    $type $userfile['type'];
          
    $name $userfile['name'];
          
    $size $userfile['size'];

          
    // if the upload succeded, the file will exist
          
    if (file_exists($tmp_name)){

             
    // check to make sure that it is an uploaded file and not a system file
             
    if(is_uploaded_file($tmp_name)){
         
                
    // open the file for a binary read
                
    $file fopen($tmp_name,'rb');
         
                
    // read the file content into a variable
                
    $data fread($file,filesize($tmp_name));

                
    // close the file
                
    fclose($file);
         
                
    // now we encode it and split it into acceptable length lines
                
    $data chunk_split(base64_encode($data));
             }
         
             
    // now we'll insert a boundary to indicate we're starting the attachment
             // we have to specify the content type, file name, and disposition as
             // an attachment, then add the file content.
             // NOTE: we don't set another boundary to indicate that the end of the 
             // file has been reached here. we only want one boundary between each file
             // we'll add the final one after the loop finishes.
             
    $message .= "--{$mime_boundary}\n" .
                
    "Content-Type: {$type};\n" .
                
    " name=\"{$name}\"\n" .
                
    "Content-Disposition: attachment;\n" .
                
    " filename=\"{$fileatt_name}\"\n" .
                
    "Content-Transfer-Encoding: base64\n\n" .
             
    $data "\n\n";
          }
       }
          
    // here's our closing mime boundary that indicates the last of the message
       
    $message.="--{$mime_boundary}--\n";
       
       
    //LINE 105, securimage code at http://www.phpcaptcha.org/documentation/quickstart/
    require_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'
    $valid $securimage->check($_POST['code']); //THIS IS LINE 107
        //Next we will actually check to see if the code was correct.
    if ($securimage->check($_POST['captcha_code']) == false) {
      
    // the code was incorrect
      // handle the error accordingly with your other error checking
    }

       
    // now we just send the message
        // formhandler2.php
     
    if (( sizeof($_POST) > 1) and ($valid == true)) {
     
    // process & validate form

     // if all data is present and "clean", then proceed
     
    if ( mail($to$subject$message$headers) ) {
       
    // mail success!
       
    header("Location: thankyou.html");
     } else {
      
    // mail failure!
      
    header("Location: tryagain.html");
     }
    }

    ?>

  • #13
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    you forgot to create the Secureimage object.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #14
    New Coder
    Join Date
    Feb 2010
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Shoot! I inserted the line and now the form goes to an empty white webpage. I assume this means it all checked out correctly, however, the form's info and file attachment never came in to my inbox either.

    I have the $valid added into the line where it goes to send the message, but it did not deliver or redirect.

    PHP Code:
    <?php session_start();
    ?>

    <?php
       
    if ($_SERVER['REQUEST_METHOD']=="POST"){

       
    // we'll begin by assigning the To address and message subject
       
    $to="jmacdesigns@gmail.com";
       
    $subject="E-mail with attachment";

       
    // get the sender's name and email address
       // we'll just plug them a variable to be used later
       
    $from stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

       
    // generate a random string to be used as the boundary marker
       
    $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

       
    // now we'll build the message headers
       
    $headers "From: $from\r\n" 
       
    "MIME-Version: 1.0\r\n" .
          
    "Content-Type: multipart/mixed;\r\n" .
          
    " boundary=\"{$mime_boundary}\"";

       
    // here, we'll start the message body. all entries ARE case sensitive!!
       // this is the text that will be displayed
       // in the e-mail
        
    $message $_POST['message'];
        
        
    $YourName $_POST['YourName'];
        
    $BizName $_POST['BizName'];
        
    $address $_POST['address'];
        
    $city $_POST['city'];
        
    $State $_POST['State'];
        
    $zipcode $_POST['zipcode'];
        
    $email $_POST['email'];
        
    $JobType $_POST['JobType'];
        
    $JobDimensions $_POST['JobDimensions'];
        
    $Quantity $_POST['Quantity'];
        
    $PaperWhite $_POST['PaperWhite'];
        
    $PaperOffWhite $_POST['PaperOffWhite'];
        
    $PaperCSWhite $_POST['PaperCSWhite'];
        
    $PaperCSOffWhite $_POST['PaperCSOffWhite'];
        
    $PaperOther $_POST['PaperOther'];
        
    $LaminationYes $_POST['LaminationYes'];
        
    $LaminationNo $_POST['LaminationNo'];
        
    $DateReq $_POST['DateReq'];
        
    $comments $_POST['comments'];
        
        
    $message"Your Name: $YourName\n\nBusiness Name: $BizName\n\nAddress: $Address\n\nCity: $City\n\nState: $State\n\nZip Code: $ZipCode\n\nEmail: $email\n\nJob Type: $JobType\n\nJob Dimensions: $JobDimensions\n\nQuantity: $Quantity\n\nPaper White: $PaperWhite\n\nPaper Off White: $PaperOffWhite\n\nPaper Card Stock White: $PaperCSWhite\n\nPaper Card Stock Off White: $PaperCSOffWhite\n\nPaper Other: $PaperOther\n\nLamination Yes: $LaminationYes\n\nLamination No: $LaminationNo\n\nDate Required: $DateReq\n\nComments: $comments\n\n";

       
    // next, we'll build the invisible portion of the message body
       // note that we insert two dashes in front of the MIME boundary 
       // when we use it
       
    $message "This is a multi-part message in MIME format.\n\n" .
          
    "--{$mime_boundary}\n" .
          
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
          
    "Content-Transfer-Encoding: 7bit\n\n" .
       
    $message "\n\n";
    }
       
    // now we'll process our uploaded files
       
    foreach($_FILES as $userfile){
          
    // store the file information to variables for easier access
          
    $tmp_name $userfile['tmp_name'];
          
    $type $userfile['type'];
          
    $name $userfile['name'];
          
    $size $userfile['size'];

          
    // if the upload succeded, the file will exist
          
    if (file_exists($tmp_name)){

             
    // check to make sure that it is an uploaded file and not a system file
             
    if(is_uploaded_file($tmp_name)){
         
                
    // open the file for a binary read
                
    $file fopen($tmp_name,'rb');
         
                
    // read the file content into a variable
                
    $data fread($file,filesize($tmp_name));

                
    // close the file
                
    fclose($file);
         
                
    // now we encode it and split it into acceptable length lines
                
    $data chunk_split(base64_encode($data));
             }
         
             
    // now we'll insert a boundary to indicate we're starting the attachment
             // we have to specify the content type, file name, and disposition as
             // an attachment, then add the file content.
             // NOTE: we don't set another boundary to indicate that the end of the 
             // file has been reached here. we only want one boundary between each file
             // we'll add the final one after the loop finishes.
             
    $message .= "--{$mime_boundary}\n" .
                
    "Content-Type: {$type};\n" .
                
    " name=\"{$name}\"\n" .
                
    "Content-Disposition: attachment;\n" .
                
    " filename=\"{$fileatt_name}\"\n" .
                
    "Content-Transfer-Encoding: base64\n\n" .
             
    $data "\n\n";
          }
       }
          
    // here's our closing mime boundary that indicates the last of the message
       
    $message.="--{$mime_boundary}--\n";
       
       
    //LINE 105, securimage code at http://www.phpcaptcha.org/documentation/quickstart/
    require_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
    $securimage = new securimage();   
    $valid $securimage->check($_POST['code']); //THIS IS LINE 108
        //Next we will actually check to see if the code was correct.
    if ($securimage->check($_POST['captcha_code']) == false) {
      
    // the code was incorrect
      // handle the error accordingly with your other error checking
    }

       
    // now we just send the message
        // formhandler2.php
     
    if (( sizeof($_POST) > 1) and ($valid == true)) {
     
    // process & validate form

     // if all data is present and "clean", then proceed
     
    if ( mail($to$subject$message$headers) ) {
       
    // mail success!
       
    header("Location: thankyou.html");
     } else {
      
    // mail failure!
      
    header("Location: tryagain.html");
     }
    }

    ?>

  • #15
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    if you’re neither at thankyou.html nor tryagain.html, then my guess is, that the captcha is not valid (the only flow, where you don’t end up at a website)
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

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