treehouse : what would you like to learn today?
Web Design Web Development iOS Development

My contact form doesnt work

  • Hi there,

    I have been looking on the internet to fix my lil problem i have with my contact form. But i doesnt seem to find the answer for it. Thats why i am going to bothering you guys here and hope you dont mind and help me out with this problem which is really small for most of you but for me its a disaster.

    My problem is as follow:
    I have a contact form in HTML when press submit it use PHP script to mail to me.
    But when error or succes it redirect to a specific page. But unfortunately i cant get this to work.

    Below is the form n HTML

    <form id=\"contact-form\" action=\"mail.php\" method=\"post\">
    <label>*Naam:</label>
    <input name=\"name\" type=\"text\">

    <label>Bedrijf/Organisatie:</label>
    <input name=\"company\" type=\"text\">
    <label>*Email:</label>
    <input name=\"email\" type=\"text\">
    <label>Contact Nr.</label>
    <input name=\"tel\" type=\"text\">
    <label>*Bericht:</label><textarea name=\"enquiry\" rows=\"12\" cols=\"1\"></textarea>
    <button type=\"submit\" class=\"positive\">Versturen</button>

    </form>
    </div>


    And here is the PHP script

    <?php

    // get posted data into local variables
    $EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
    $EmailTo = \"wing72@gmail.com\";
    $Subject = \"Mail vanuit website\";
    $name = Trim(stripslashes($_POST['name']));
    $company = Trim(stripslashes($_POST['company']));
    $tel = Trim(stripslashes($_POST['tel']));
    $email = Trim(stripslashes($_POST['email']));
    $message = Trim(stripslashes($_POST['message']));

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

    // prepare email body text
    $Body = \"\";
    $Body .= \"name: \";
    $Body .= $name;
    $Body .= \"\n\";
    $Body .= \"company: \";
    $Body .= $company;
    $Body .= \"\n\";
    $Body .= \"tel: \";
    $Body .= $tel;
    $Body .= \"\n\";
    $Body .= \"email: \";
    $Body .= $email;
    $Body .= \"\n\";
    $Body .= \"message: \";
    $Body .= $message;
    $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=contact.html\\">\";
    }
    else{
    print \"<meta http-equiv=\\"refresh\\" content=\\"0;URL=contact-error.html\\">\";
    }
    ?>


    I hope you guys can help me out,

    Thanks Alot for your time
  • Is there anyone who can help me out with this bit pls ..
  • Not sure what you are asking.
    The whole thing doesn't work or just the page redirect?
  • thnx for you time, well its the whole thing that doesnt work.
    It doesnt send any mail out and it keep redirecting to the error page not matter what.

    wing
  • doing a basic test can help see where it is dying, like at each stage, write something out to the page:
    e.g. if your php filled the body of the mail, echo it out, perform something for each stage to see when it dies...
    echo = "body populated";

    "wingye" said:
    thnx for you time, well its the whole thing that doesnt work.
    It doesnt send any mail out and it keep redirecting to the error page not matter what.

    wing


    are you on a windows server?
    if so you need to set your ini in php

    plus enquiry & message are not the same!!! you might want to change one.

    mind you it looks like the script I use, but I $_REQUEST my HTML elements

    e.g.

    $name = $_REQUEST['name'];
    $tel = $_REQUEST['tel'];
    $email = $_REQUEST['email'];


    also this is my success:
    $success = mail($EmailTo, $Subject, $Body, "From: <$email>", "-froot@my-email-address");

    hopefully these small hints may help get it working
  • Maybe I can help you with your problem. I have written an article on my blog on creating a contact form using PHP and jQuery for validation. It's really simple and short. I hope you will find my article helpful. Thank you.

    http://www.raymondselda.com/php-contact ... alidation/