Php contact form error

Discussion in 'PHP' started by nura235, May 3, 2010.

  1. #1
    Hi,
    i m using the below php form to get contacted by visitor but always it redirected to error page.

    <?PHP
    error_reporting(7);
    
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
     $ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
     $ClientIP = $_SERVER['REMOTE_ADDR'];
    }
    
    
    $FTGname = $_POST['name'];
    $FTGemail = $_POST['email'];
    $FTGcity = $_POST['city'];
    $FTGphone = $_POST['phone'];
    $FTGmessage = $_POST['message'];
    $FTGSubmit = $_POST['Submit'];
    $FTGReset = $_POST['Reset'];
    
    $FTGselect = $select;
    $FTGname = $name;
    $FTGemail = $email;
    #$FTGtitle = $title;
    #$FTGcompany = $company;
    #$FTGwebsite = $website;
    $FTGcity = $city;
    #$FTGcountry = $country;
    $FTGphone = $phone;
    #$FTGfax = $fax;
    #$FTGbusiness = $business;
    #$FTGmessage = $message;
    $FTGSubmit = $Submit;
    $FTGReset = $Reset;
    
    #if (get_magic_quotes_gpc) {
    
     #$FTGselect = DoStripSlashes( $_REQUEST['select'] );
     #$FTGname = DoStripSlashes( $_REQUEST['name'] );
     #$FTGemail = DoStripSlashes( $_REQUEST['email'] ); 
     #$FTGtitle = DoStripSlashes( $_REQUEST['title'] );
     #$FTGcompany = DoStripSlashes( $_REQUEST['company'] ); 
     #$FTGwebsite = DoStripSlashes( $_REQUEST['website'] );  
     #$FTGcity = DoStripSlashes( $_REQUEST['city'] );  
     #$FTGcountry = DoStripSlashes( $_REQUEST['country'] );  
     #$FTGphone = DoStripSlashes( $_REQUEST['phone'] );  
      #$FTGfax = DoStripSlashes( $_REQUEST['fax'] );    
     # $FTGbusiness = DoStripSlashes( $_REQUEST['business'] );  
     #$FTGmessage =DoStripSlashes( $_REQUEST['message'] );   
      #$FTGSubmit = DoStripSlashes( $_REQUEST['Submit'] );   
     #$FTGReset = DoStripSlashes( $_REQUEST['Reset'] );  
    
     $FTGname = stripslashes($FTGname);
     $FTGemail = stripslashes($FTGemail);
     $FTGcity = stripslashes($FTGcity);
     $FTGphone = stripslashes($FTGphone);
     $FTGmessage = stripslashes($FTGmessage);
     $FTGSubmit = stripslashes($FTGSubmit);
     $FTGReset = stripslashes($FTGReset);
    #}
    # Redirect user to the error page
    
    if ($validationFailed == false) {
    
     header("Location: error.html");
     exit;
    
    }
    
    # Email to Form Owner
    
    $emailTo = '"nura235@gmail.com" <nura235@gmail.com>';
    
    $emailSubject = "Form details for AA Patent Drawings";
    $emailSubject = preg_replace('/[\x00-\x1F]/', '', $emailSubject);
    
    $emailFrom = "$FTGemail";
    $emailFrom = preg_replace('/[\x00-\x1F]/', '', $emailFrom);
    
    $emailBody = "name: $FTGname\n"
     . "email: $FTGemail\n"
     . "city: $FTGcity\n"
     . "phone: $FTGphone\n"
     . "message: $FTGmessage\n"
     . "\n"
     . "";
    
    $emailHeader = "From: $emailFrom\n"
     . "Reply-To: $emailFrom\n"
     . "MIME-Version: 1.0\n"
     . "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
     . "Content-transfer-encoding: 8bit\n";
    
    mail($emailTo, $emailSubject, $emailBody, $emailHeader);
    
    # Confirmation Email to User
    
    #$confEmailTo = $FTGemail;
    #$confEmailTo = preg_replace('/[\x00-\x1F]/', '', $confEmailTo);
    
    #$confEmailSubject = "Thank you for contacting us";
    #$confEmailSubject = preg_replace('/[\x00-\x1F]/', '', $confEmailSubject);
    
    #$confEmailBody = "Dear $FTGname,\n"
     #. "Thanks for contacting us, one of our representatives will contact you within 24 hours.\n"
     #. "\n"
     #. "Following are the details submitted by you :-\n"
     #. "name: $FTGname\n"
     #. "email: $FTGemail\n"
     #. "city: $FTGcity\n"
     #. "phone: $FTGphone\n"
     #. "message: $FTGmessage\n"
     #. "\n"
     #. "Yours,\n"
     #. "AA Patent Drawings";
    
    $confEmailHeader = "From: nura235@gmail.com\n"
     . "Reply-To: nura235@gmail.com\n"
     . "MIME-Version: 1.0\n"
     . "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
     . "Content-transfer-encoding: 8bit\n";
    
    mail($confEmailTo, $confEmailSubject, $confEmailBody, $confEmailHeader);
    
    # Redirect user to success page
    
    header("Location: thanks.html");
    exit;
    
    # End of PHP script
    ?>
    PHP:
    i m using this form here
    http://www.aapatentdrawings.com/contact-us.html
    Code (markup):
     
    nura235, May 3, 2010 IP
  2. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #2
    You can't troubleshoot a PHP application with error reporting set to a useless level.

    Line 2 should read:
     
    zac439, May 4, 2010 IP
  3. extremephp

    extremephp Peon

    Messages:
    1,290
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Using PHP in contact pages is really a mess dude..!

    Instead Use HTML+CSS for contact page structure and Use PHP to get it mailed to your Email..!

    That would be easy for you..! :)

    Just a suggestion :)

    This is just a suggestion, And Sorry if you feel am bumping the thread. I can delete this post if you feel so...! :)

    Thanks.
     
    Last edited: May 4, 2010
    extremephp, May 4, 2010 IP
  4. nura235

    nura235 Well-Known Member

    Messages:
    529
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Changing the code giving error in line 15, 16, 18m 19, 20, 24, 26, 30, 31 and 60
     
    nura235, May 4, 2010 IP
  5. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #5
    Take a look at this error:
    Warning: Cannot modify header information - headers already sent by (output started at [path]) in [path] on line 62

    It is telling you that the headers were already sent. Headers might include the session, cookies, and so forth.
    You can buffer the output by using ob_start();

     
    zac439, May 4, 2010 IP
  6. bytes

    bytes Peon

    Messages:
    39
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    seems that you're using lots of uncdefined variables:
    
    $FTGselect = $select;
    $FTGname = $name;
    $FTGemail = $email;
    
    PHP:
    those on the right side are undefined. Also,

    
    $validationFailed == false
    
    PHP:
    $validationFailed will always be null (undefined) there yielding to false with ==. That's why probably you're always redirected
     
    bytes, May 4, 2010 IP
  7. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #7
    Change contact page script or remove

    And in something inc.php search for $validation and remove that!
    Still if you can't resolve PM me the whole thing
     
    roopajyothi, May 4, 2010 IP
  8. nura235

    nura235 Well-Known Member

    Messages:
    529
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    110
    #8
    i just made it work

    $validationFailed == true
    PHP:
    but making true, dont check if form is blank or any error
     
    nura235, May 4, 2010 IP
  9. nura235

    nura235 Well-Known Member

    Messages:
    529
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    110
    #9
    nura235, May 4, 2010 IP
  10. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #10
    Really nice one!
    Works fine :)
     
    roopajyothi, May 4, 2010 IP
  11. zac439

    zac439 Notable Member

    Messages:
    3,074
    Likes Received:
    214
    Best Answers:
    0
    Trophy Points:
    260
    #11
    An automatically generated form.. the best way to not learn anything about PHP!
    I would recommend you find a good tutorial and make a form yourself.

    The skills you learn as a developer are invaluable.
     
    zac439, May 4, 2010 IP
  12. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #12
    Your demo: http://www.aapatentdrawings.com/contact-us.html html for the form is totally different to the code you posted??. Furthermore your code is a mess undefined variables and so on. I suggest you recode from scratch or atleast reply with the html for your contact form so we can assist you with the php to go with it.
     
    danx10, May 4, 2010 IP
  13. nura235

    nura235 Well-Known Member

    Messages:
    529
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    110
    #13
    Yes i agree with your word, but i m not a professional programmer, just only know playing with some of php codes, anyway thanks for your help, i assume that my current code is much better than previous one, it give alert instantly when something goes wrong, while on php it give error after submit.


    Yes this is bcoz i find the correct working another code.
     
    nura235, May 4, 2010 IP