Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] Simple contact form help

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #30317
    j1300
    Member

    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

    
    
    $EmailFrom = "My website Enquiry";
    $EmailTo = "[email protected]";
    $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: [email protected]
    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

    #79269
    ImpInaBox
    Member

    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!

    #79243
    j1300
    Member

    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)
  • The forum ‘Back End’ is closed to new topics and replies.