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.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form always sends to error page...

    Hello,
    Any help will be greatly appreciated. If I fill out every field I am still sent to the error page. Are there any errors? Thank you!

    Link to same question on a different forum: PHP Phreaks - Topic: Form always sends to error page...

    Web Site: CPA Contact Form

    ===========================================================

    PHP Code:
    <?php

    $mailto 
    'joseph@charitableprofitarrangement.org' ;
    $subject "CPA Contact Form" ;
    $formurl "http://www.charitableprofitarrangement.org/contact.html" ;
    $errorurl "http://www.charitableprofitarrangement.org/error.html" ;
    $thankyouurl "http://www.charitableprofitarrangement.org/thankyou.html" ;

    $valid_points 0;
    $uself 0;
    $use_envsender 0;
    $use_sendmailfrom 0;
    $use_webmaster_email_for_from 0;
    $use_utf8 1;

    $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" "\n" ;
    $content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' 'Content-Type: text/plain; charset="utf-8"' ;
    if (isset( 
    $use_sendmailfrom ) && $use_sendmailfrom) {
        
    ini_set'sendmail_from'$mailto );
    }
    $envsender "-f$mailto" ;
    $firstname $_POST['firstname'] ;
    $lastname $_POST['lastname'] ;
    $organization $_POST['organization'] ;
    $city $_POST['city'] ;
    $state $_POST['state'] ;
    $phone $_POST['phone'] ;
    $email $_POST['email'] ;
    $website $_POST['website'] ;
    $subject $_POST['subject'] ;
    $message $_POST['message'] ;
    $http_referrer getenv"HTTP_REFERER" );

    if (!isset(
    $_POST['email'])) {
        
    header"Location: $formurl" );
        exit ;
    }

    if (
    preg_match"/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/im"$email)) $valid_points++ ;
    if (
    preg_match"/[\r\n]/"$firstname)) $valid_points++ ;
    if (
    preg_match"/[\r\n]/"$lastname)) $valid_points++ ;
    if (
    preg_match"/[\r\n]/"$organization)) $valid_points++ ; 
    if (
    preg_match"/[\r\n]/"$city)) $valid_points++ ;
    if (
    preg_match"/[\r\n]/"$state)) $valid_points++ ;
    if (
    preg_match"/^\\d{10}$/m"$phone)) $valid_points++ ;
    if (
    preg_match"/[\r\n]/"$website)) $valid_points++ ;
    if (
    preg_match"/[\r\n]/"$subject)) $valid_points++ ;
    if (
    preg_match"/[\r\n]/"$message)) $valid_points++ ;
    if (!empty(
    $email)) $valid_points++ ;
    if (!empty(
    $firstname)) $valid_points++ ;
    if (!empty(
    $lastname)) $valid_points++ ;
    if (!empty(
    $city)) $valid_points++ ;
    if (!empty(
    $state)) $valid_points++ ;
    if (!empty(
    $subject)) $valid_points++ ;
    if (!empty(
    $message)) $valid_points++ ;

    if (empty(
    $email)) {
        
    $email $mailto ;
    }

    $fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email $mailto ;

    if (
    get_magic_quotes_gpc()) {
        
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
        while (list(
    $key$val) = each($process)) {
            foreach (
    $val as $k => $v) {
                unset(
    $process[$key][$k]);
                if (
    is_array($v)) {
                    
    $process[$key][stripslashes($k)] = $v;
                    
    $process[] = &$process[$key][stripslashes($k)];
                } else {
                    
    $process[$key][stripslashes($k)] = stripslashes($v);
                }
            }
        }
        unset(
    $process);
    }

    $messageproper =
        
    "This message was sent from:\n" .
        
    "$http_referrer\n" .
        
    "------------------------------------------------------------\n" .
        
    "First Name: $firstname\n" .
        
    "Last Name: $lastname\n" .
        
    "Organization: $organization\n" .
        
    "City: $city\n" .
        
    "State: $state\n" .
        
    "Phone: $phone\n" .
        
    "Email: $email\n" .
        
    "Website: $website\n" .
        
    "Subject: $subject\n" .
        
    "------------------------- MESSAGE -------------------------\n\n" .
        
    $message .
        
    "\n\n------------------------------------------------------------\n" ;

    $headers =
        
    "From: \"$firstname\" <$fromemail>" $headersep "Reply-To: \"$firstname\" <$email>" $headersep "X-Mailer: chfeedback.php 2.15.0" $headersep 'MIME-Version: 1.0' $headersep $content_type ;

    if ((
    $validpoints == 17) && ($use_envsender)) {
        
    mail$mailto$subject$messageproper$headers$envsender );
    }
    else {
        
    header"Location: $errorurl" );
        exit ;
    }

    header"Location: $thankyouurl" );
    exit ;

    ?>

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I don't see $use_envsender ever set to anything but 0, so your condition if (($validpoints == 17) && ($use_envsender)) will always evaluate false.

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oops, I forgot this line:

    PHP Code:
    if (!isset( $use_envsender )) { $use_envsender ; } 
    would that even make a difference?

    I am going to see if the code works with envsender and use_envsender removed.

    Thanks for the quick reply!

  • #4
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's the updated code... still sends to error page:

    PHP Code:
    <?php

    $mailto 
    'joseph@charitableprofitarrangement.org' ;
    $subject "CPA Contact Form" ;
    $formurl "http://www.charitableprofitarrangement.org/contact.html" ;
    $errorurl "http://www.charitableprofitarrangement.org/error.html" ;
    $thankyouurl "http://www.charitableprofitarrangement.org/thankyou.html" ;

    $valid_points 0;
    $uself 0;
    $use_sendmailfrom 0;
    $use_webmaster_email_for_from 0;
    $use_utf8 1;
    $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" "\n" ;
    $content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' 'Content-Type: text/plain; charset="utf-8"' ;
    if (isset( 
    $use_sendmailfrom ) && $use_sendmailfrom) {
        
    ini_set'sendmail_from'$mailto );
    }
    $firstname $_POST['firstname'] ;
    $lastname $_POST['lastname'] ;
    $organization $_POST['organization'] ;
    $city $_POST['city'] ;
    $state $_POST['state'] ;
    $phone $_POST['phone'] ;
    $email $_POST['email'] ;
    $website $_POST['website'] ;
    $subject $_POST['subject'] ;
    $message $_POST['message'] ;
    $http_referrer getenv"HTTP_REFERER" );

    if (!isset(
    $_POST['email'])) {
        
    header"Location: $formurl" );
        exit ;
    }

    if (
    preg_match'/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/im'$email)) $valid_points++ ;
    if (
    preg_match'/[\r\n]/'$firstname)) $valid_points++ ;
    if (
    preg_match'/[\r\n]/'$lastname)) $valid_points++ ;
    if (
    preg_match'/[\r\n]/'$organization)) $valid_points++ ; 
    if (
    preg_match'/[\r\n]/'$city)) $valid_points++ ;
    if (
    preg_match'/[\r\n]/'$state)) $valid_points++ ;
    if (
    preg_match'/^\\d{10}$/m'$phone)) $valid_points++ ;
    if (
    preg_match'/[\r\n]/'$website)) $valid_points++ ;
    if (
    preg_match'/[\r\n]/'$subject)) $valid_points++ ;
    if (
    preg_match'/[\r\n]/'$message)) $valid_points++ ;
    if (!empty(
    $email)) $valid_points++ ;
    if (!empty(
    $firstname)) $valid_points++ ;
    if (!empty(
    $lastname)) $valid_points++ ;
    if (!empty(
    $city)) $valid_points++ ;
    if (!empty(
    $state)) $valid_points++ ;
    if (!empty(
    $subject)) $valid_points++ ;
    if (!empty(
    $message)) $valid_points++ ;

    if (empty(
    $email)) {
        
    $email $mailto ;
    }

    $fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email $mailto ;

    if (
    get_magic_quotes_gpc()) {
        
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
        while (list(
    $key$val) = each($process)) {
            foreach (
    $val as $k => $v) {
                unset(
    $process[$key][$k]);
                if (
    is_array($v)) {
                    
    $process[$key][stripslashes($k)] = $v;
                    
    $process[] = &$process[$key][stripslashes($k)];
                } else {
                    
    $process[$key][stripslashes($k)] = stripslashes($v);
                }
            }
        }
        unset(
    $process);
    }

    $messageproper =
        
    "This message was sent from:\n" .
        
    "$http_referrer\n" .
        
    "------------------------------------------------------------\n" .
        
    "First Name: $firstname\n" .
        
    "Last Name: $lastname\n" .
        
    "Organization: $organization\n" .
        
    "City: $city\n" .
        
    "State: $state\n" .
        
    "Phone: $phone\n" .
        
    "Email: $email\n" .
        
    "Website: $website\n" .
        
    "Subject: $subject\n" .
        
    "------------------------- MESSAGE -------------------------\n\n" .
        
    $message .
        
    "\n\n------------------------------------------------------------\n" ;

    $headers =
        
    "From: \"$firstname\" <$fromemail>" $headersep "Reply-To: \"$firstname\" <$email>" $headersep "X-Mailer: chfeedback.php 2.15.0" $headersep 'MIME-Version: 1.0' $headersep $content_type ;

    if (
    $valid_points == 17) {
        
    mail$mailto$subject$messageproper$headers );
    }
    else {
        
    header"Location: $errorurl" );
        exit ;
    }

    header"Location: $thankyouurl" );
    exit ;

    ?>
    This original generated script works fine, but does not have all the checks and required fields I want:

    PHP Code:
    <?php

    $mailto 
    'joseph@charitableprofitarrangement.org' ;
    $subject "Feedback Form" ;
    $formurl "http://www.charitableprofitarrangement.org/contact.html" ;
    $errorurl "http://www.charitableprofitarrangement.org/error.html" ;
    $thankyouurl "http://www.charitableprofitarrangement.org/thankyou.html" ;

    $email_is_required 1;
    $name_is_required 1;
    $comments_is_required 1;
    $uself 0;
    $use_envsender 0;
    $use_sendmailfrom 0;
    $use_webmaster_email_for_from 0;
    $use_utf8 1;
    $my_recaptcha_private_key '' ;

    $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" "\n" ;
    $content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' 'Content-Type: text/plain; charset="utf-8"' ;
    if (!isset( 
    $use_envsender )) { $use_envsender ; }
    if (isset( 
    $use_sendmailfrom ) && $use_sendmailfrom) {
        
    ini_set'sendmail_from'$mailto );
    }
    $envsender "-f$mailto" ;
    $fullname = (isset($_POST['fullname']))? $_POST['fullname'] : $_POST['name'] ;
    $email $_POST['email'] ;
    $comments $_POST['comments'] ;
    $http_referrer getenv"HTTP_REFERER" );

    if (!isset(
    $_POST['email'])) {
        
    header"Location: $formurl" );
        exit ;
    }
    if ((
    $email_is_required && (empty($email) || !preg_match('/@/'$email))) || ($name_is_required && empty($fullname)) || ($comments_is_required && empty($comments))) {
        
    header"Location: $errorurl" );
        exit ;
    }
    if ( 
    preg_match"/[\r\n]/"$fullname ) || preg_match"/[\r\n]/"$email ) ) {
        
    header"Location: $errorurl" );
        exit ;
    }
    if (
    strlen$my_recaptcha_private_key )) {
        require_once( 
    'recaptchalib.php' );
        
    $resp recaptcha_check_answer $my_recaptcha_private_key$_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] );
        if (!
    $resp->is_valid) {
            
    header"Location: $errorurl" );
            exit ;
        }
    }
    if (empty(
    $email)) {
        
    $email $mailto ;
    }
    $fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email $mailto ;

    if (
    function_exists'get_magic_quotes_gpc' ) && get_magic_quotes_gpc()) {
        
    $comments stripslashes$comments );
    }

    $messageproper =
        
    "This message was sent from:\n" .
        
    "$http_referrer\n" .
        
    "------------------------------------------------------------\n" .
        
    "Name of sender: $fullname\n" .
        
    "Email of sender: $email\n" .
        
    "------------------------- COMMENTS -------------------------\n\n" .
        
    $comments .
        
    "\n\n------------------------------------------------------------\n" ;

    $headers =
        
    "From: \"$fullname\" <$fromemail>" $headersep "Reply-To: \"$fullname\" <$email>" $headersep "X-Mailer: chfeedback.php 2.15.0" .
        
    $headersep 'MIME-Version: 1.0' $headersep $content_type ;

    if (
    $use_envsender) {
        
    mail($mailto$subject$messageproper$headers$envsender );
    }
    else {
        
    mail($mailto$subject$messageproper$headers );
    }
    header"Location: $thankyouurl" );
    exit ;

    ?>

  • #5
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Got it to work! Here's the code for anyone else making a form:

    PHP Code:
    <?php

    $mailto 
    'your@email.com' ;
    $subject "Your Contact Form" ;
    $formurl "http://www.yoursite.com/contact.html" ;
    $errorurl "http://www.yoursite.com/error.html" ;
    $thankyouurl "http://www.yoursite.com/thankyou.html" ;
    $uself 0;
    $use_sendmailfrom 0;
    $use_webmaster_email_for_from 0;
    $use_utf8 1;
    $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" "\n" ;
    $content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' 'Content-Type: text/plain; charset="utf-8"' ;
    if (isset( 
    $use_sendmailfrom ) && $use_sendmailfrom) {
            
    ini_set'sendmail_from'$mailto );
    }
    $firstname addslashes($_POST['firstname']) ;
    $lastname addslashes($_POST['lastname']) ;
    $city addslashes($_POST['city']) ;
    $state addslashes($_POST['state']) ;
    $phone addslashes($_POST['phone']) ;
    $email addslashes($_POST['email']) ;
    $website addslashes($_POST['website']) ;
    $subject addslashes($_POST['subject']) ;
    $message addslashes($_POST['message']) ;
    $http_referrer getenv"HTTP_REFERER" );

    if (!isset(
    $_POST['email'])) {
            
    header"Location: $formurl" );
            exit ;
    }

    $valid_email = (preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/im'$email)) ? true false;
    $valid_firstname = (!empty($firstname)) ? true false;
    $valid_lastname = (!empty($lastname)) ? true false;
    $valid_city = (!empty($city)) ? true false;
    $valid_state = (!empty($state)) ? true false;
    $valid_message = (!empty($subject) && !empty($message)) ? true false;

    $fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email $mailto ;

    if (
    get_magic_quotes_gpc()) {
        
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
        while (list(
    $key$val) = each($process)) {
            foreach (
    $val as $k => $v) {
                unset(
    $process[$key][$k]);
                if (
    is_array($v)) {
                    
    $process[$key][stripslashes($k)] = $v;
                    
    $process[] = &$process[$key][stripslashes($k)];
                } else {
                    
    $process[$key][stripslashes($k)] = stripslashes($v);
                }
            }
        }
        unset(
    $process);
    }

    $messageproper 
            
    "This message was sent from:\n" .
            
    "$http_referrer\n" .
            
    "------------------------------------------------------------\n" .
            
    "First Name: $firstname\n" .
            
    "Last Name: $lastname\n" .
            
    "City: $city\n" .
            
    "State: $state\n" .
            
    "Phone: $phone\n" .
            
    "Email: $email\n" .
            
    "Website: $website\n" .
            
    "Subject: $subject\n" .
            
    "------------------------- MESSAGE -------------------------\n\n" .
            
    $message .
            
    "\n\n------------------------------------------------------------\n" ;

    $headers "From: \"$firstname\" <$fromemail>" $headersep "Reply-To: \"$firstname\" <$email>" $headersep "X-Mailer: chfeedback.php 2.15.0" $headersep 'MIME-Version: 1.0' $headersep $content_type ;

    if (
    $valid_email && $valid_firstname && $valid_lastname && $valid_city && $valid_state && $valid_message) {
            
    mail $mailto$subject$messageproper$headers );
    }
    else {
            
    header"Location: $errorurl" );
            exit ;
    }

    header"Location: $thankyouurl" );
    exit ;

    ?>
    Last edited by cpawebmaster; 02-20-2010 at 12:41 PM.


  •  

    Posting Permissions

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