website contact form not working

Discussion in 'OT Technology' started by craigl33, May 15, 2008.

  1. craigl33

    craigl33 New Member

    Joined:
    Jul 17, 2006
    Messages:
    357
    Likes Received:
    0
    my form doesn't work. can anyone help me?

    here's the code in the html file:

    <form method="POST" action="contact2.php">
    Fields marked (*) are required

    <p>Email From:* <br>
    <input type="text" name="EmailFrom">
    <p>FirstName:<br>
    <input type="text" name="FirstName">
    <p>LastName:<br>
    <input type="text" name="LastName">
    <p>HomeTel:<br>
    <input type="text" name="HomeTel">
    <p><input type="submit" name="submit" value="Submit">
    </form>


    and here's the php file:

    <?php

    $EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
    $EmailTo = "[email protected]";
    $Subject = "Testing";
    $FirstName = Trim(stripslashes($_POST['FirstName']));
    $LastName = Trim(stripslashes($_POST['LastName']));
    $HomeTel = Trim(stripslashes($_POST['HomeTel']));

    // validation
    $validationOK=true;
    if (Trim($EmailFrom)=="") $validationOK=false;
    if (!$validationOK) {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
    exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "FirstName: ";
    $Body .= $FirstName;
    $Body .= "\n";
    $Body .= "LastName: ";
    $Body .= $LastName;
    $Body .= "\n";
    $Body .= "HomeTel: ";
    $Body .= $HomeTel;
    $Body .= "\n";

    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

    // redirect to success page
    if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
    }
    else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
    }
    ?>
     
  2. ge0

    ge0 New Member

    Joined:
    Oct 31, 2005
    Messages:
    8,398
    Likes Received:
    0
    Location:
    JERSEY
    Is any variables being passed? What do you mena by NOT working?
     
  3. Mike99TA

    Mike99TA I don't have anything clever to put here right now

    Joined:
    Oct 3, 2001
    Messages:
    4,553
    Likes Received:
    0
    Location:
    Greenville, SC
    Not sure the difference between php and perl, but in perl if you do $EmailTo = "[email protected]" you would have to escape the @ to prevent it from referencing the array @blah, so it would have to be "blah\@blah.com" - if it seems to work but you're not getting an e-mail, check that. Other than that I don't do PHP really, and you'll need to provide a lot more detail than "it doesn't work". What part seems to be failing, have you tried debugging statements and printing them to the browser, etc.
     
    Last edited: May 16, 2008
  4. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    .

    Need a little more information.

    PHP doesn't mind the @ symbol being in the "s.
     
  5. craigl33

    craigl33 New Member

    Joined:
    Jul 17, 2006
    Messages:
    357
    Likes Received:
    0
    when i click submit it goes to the php page and spits this out:

    "; exit; } // prepare email body text $Body = ""; $Body .= "FirstName: "; $Body .= $FirstName; $Body .= "\n"; $Body .= "LastName: "; $Body .= $LastName; $Body .= "\n"; $Body .= "HomeTel: "; $Body .= $HomeTel; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print ""; } else{ print ""; } ?>
     
  6. Mike99TA

    Mike99TA I don't have anything clever to put here right now

    Joined:
    Oct 3, 2001
    Messages:
    4,553
    Likes Received:
    0
    Location:
    Greenville, SC
    Based on that, I'm guessing

    $validationOK=true;
    if (Trim($EmailFrom)=="") $validationOK=false;

    should be

    $validationOK=true;
    if (Trim($EmailFrom)=="") { $validationOK=false; }
     
  7. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    looks good to me. if it's spitting out actual php code your server set up may be the problem.

    that shouldn't make a difference.
     
  8. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    Sounds like when you FTP'd it something went wrong. Try uploading again.
     
  9. Mike99TA

    Mike99TA I don't have anything clever to put here right now

    Joined:
    Oct 3, 2001
    Messages:
    4,553
    Likes Received:
    0
    Location:
    Greenville, SC
    Uh...why wouldn't the braces make a difference? He has a very similar if statement directly below that one that does have the braces. If its not required, why put braces after one if statement but not after the other if statement? Its either wrong, or just bad coding.

    Edit: to show what i meant

    No braces:
    if (Trim($EmailFrom)=="") $validationOK=false;

    Braces:
    if (!$validationOK) {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
    exit;
    }

    Why is it ok on the first one but not the second one? Languages are typically very very picky about where you have braces, and if PHP doesn't care whether you have braces to enclose the block of code from an if statement thats just shitty.
     
  10. critter783

    critter783 OT Supporter

    Joined:
    Jul 15, 2005
    Messages:
    1,785
    Likes Received:
    0
    Its ok because one if statement executes one command, and the other executes multiple commands.

    Edit: Its the same in C, C++, Java, and 11ty billion other languages.
     
  11. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    :werd: and perl. in fact in perl with 1 line 'if' statements you can even put it before the condition like this:

    $num = 1 if $num >1;
     
  12. White Stormy

    White Stormy Take that, subspace!

    Joined:
    Sep 17, 2002
    Messages:
    85,486
    Likes Received:
    69
    Location:
    Sparkopolis
    worked fine for me
     

Share This Page