Grow your CSS skills. Land your dream job.

[Solved] Simple contact form help

  • # September 22, 2010 at 11:20 am

    I know that you guys must get a lot of these requests but this is my first contact form and ive literally been staring at this code for hours!

    I tried using the form available here (after not being able to do another one)

    Ive tried to add a dropdown box but am unable to get the email to contain the phone number and subject (chosen from the drop down box)

    the html used is:






















    PHP in contactengine.php

    < ?php

    $EmailFrom = "My website Enquiry";
    $EmailTo = "Bloggs@gmail.com";
    $Subject = Trim(stripslashes($_POST));
    $Name = Trim(stripslashes($_POST));
    $Tel = Trim(stripslashes($_POST));
    $Email = Trim(stripslashes($_POST));
    $Message = Trim(stripslashes($_POST));

    // validation
    $validationOK=true;
    if (!$validationOK) {
    print "";
    exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "n";
    $Body .= "Subject: ";
    $Body .= $Subject;
    $Body .= "n";
    $Body .= "Phone: ";
    $Body .= $Phone;
    $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 "";
    }
    else{
    print "";
    }
    ?>

    The emails I am getting are as below:


    Name: Joe Bloggs
    Subject:
    Phone:
    Email: Bloggs@gmail.com
    Message: Test message……………………..



    With no phone number or subject (from the drop down box). How can I fix this?

    Any help at all would be greatly appreciated!
    Thanks in advance

    # September 22, 2010 at 4:37 pm

    Your select tag for Subject is actually called ‘dropown’ not ‘Subject’. It will appear to your form processor as $_POST.
    Change <select name=”dropdown”> to <select name=”Phone”>

    The $_POST field is being put into $Tel not $Phone.
    Change $Tel = $_POST; to $Phone = $_POST;

    I would add too that you should probably validate the fields that your user can type into to check they don’t contain MIME codes aimed at hijacking your mailserver. Probably best to get the thing working first tho – worry about the rest later!

    # September 22, 2010 at 7:08 pm

    Thanks alot ImpInaBox!!

    All up and working now :) will look into validating the text (the form that I tried before this one did it, so will take a look and try and understand)

    Thanks again! its much appreciated

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".