php form issue

  • Started
  • Last post
  • 7 Responses
  • hiatus

    Not a php expert. having issue sending all the items. when I have it send only 1-2 item(like last nname & email) its fine. but I've added item to this ad cant get it to send me anything!
    Please advice thanks,
    PHP CODE:
    function isInjected($str) {
    $injections = array('(\n+)',
    '(\r+)',
    '(\t+)',
    '(%0A+)',
    '(%0D+)',
    '(%08+)',
    '(%09+)'
    );
    $inject = join('|', $injections);
    $inject = "/$inject/i";
    if(preg_match($inject,$str)) {
    return true;
    }
    else {
    return false;
    }
    }

    // Load form field data into variables.
    $first_name = $_REQUEST['first_name'];
    $last_name = $_REQUEST['last_name'];
    $company = $_REQUEST['company'];
    $email_address = $_REQUEST['email_address'] ;
    $comments = $_REQUEST['comments'] ;

    // If the user tries to access this script directly, redirect them to feedback form,
    if (!isset($_REQUEST['email_address... {
    header( "Location: feedback_form.html" );
    }

    // If the form fields are empty, redirect to the error page.
    elseif (empty($first_name) || empty($last_name) || empty($company) || empty($email_address)) {
    header( "Location: error_message.html" );
    }

    // If email injection is detected, redirect to the error page.
    elseif ( isInjected($email_address) ) {
    header( "Location: error_message.html" );
    }

    // If we passed all previous tests, send the email!
    mail( , "Seminar Result", $first_name, $last_name, $company, "From: $email_address" );
    header( "Location: thank_you.html" );

  • hiatus0

    I'm thinking the // Load form field data into variables. Aren't set right.
    I think i should re-write the mail ()
    not really sure.
    should I also not even have the validating stuff.

  • acescence0

    REQUEST contains everything- GET, POST, and COOKIE. you may have some name collision going on. if your form is using POST or GET, change REQUEST to that instead. also, add some sanity checks, echo all of your form data before the mail function to see what you've got.

    • this guys really knowledgeable & and extremely helpfulversion3
    • or girl, i'm not really sureversion3
    • treat yourself like you're a 10 year old kid coding - echo echo echo, comment comment comment....mikotondria3
    • i'm a hermaphroditeacescence
  • welded0

    You mail function is all jacked up. Take a look at the manual. http://ca2.php.net/manual/en/fun…

    Basically it's mail('recipient email', 'subject', 'message', 'other stuff you might not need') so you'll probably want to use something like this:
    , "Seminar Result", "$first_name, $last_name, $company", "From: $email_address" );

  • hiatus0

    welded, I would love to buy you a pint!

    Thanks so much!
    -one

  • vaxorcist0

    You could separate things a bit, so you can have a more readable email sent....

    $message = "
    Hello, this is from:
    $first_name, $last_name,
    at the company : $company
    ";

    , "Seminar Result", $message, "From: $email_address" );

  • acescence0

    i'd also put it inside an if, in case it fails...

    if(mail()){
    // mail succeeded
    } else {
    // mail failed
    }

  • moth0

    var_dump($_POST); < Very useful for quickly dumping out the contents of the post(or any) array.