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

Contact Form

  • I am trying to use Chris' contact form http://css-tricks.com/examples/NiceSimpleContactForm2/ in a site i am making, but i cannot get the PHP to work properly. It only sends:
    Name:
    Email:
    Message:

    and none of the actual content.

    Here is the PHP im using:
    <?php
    $EmailFrom = \"my-email-address\";
    $EmailTo = \"my-email-address\";
    $Subject = \"Query from Website\";
    $Name = Trim(stripslashes($_POST['Name']));
    $Email = Trim(stripslashes($_POST['Email']));
    $Message = Trim(stripslashes($_POST['Message']));

    // prepare email body text
    $Body = \"\";
    $Body .= \"Name: \";
    $Body .= $Name;
    $Body .= \"\n\";
    $Body .= \"Email: \";
    $Body .= $Email;
    $Body .= \"\n\";
    $Body .= \"Message: \";
    $Body .= $Message;
    $Body .= \"\n\";

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

    ?>


    and heres my form:

    <form action=\"send.php\" id=\"contact\">
    <label for=\"Name\">Your name:</label>
    <input type=\"text\" id=\"Name\" name=\"Name\" />
    <label for=\"Email\">Your email:</label>
    <input type=\"text\" id=\"Email\" name=\"Email\" />
    <label for=\"Message\">Your message:</label>
    <textarea type=\"text\" id=\"Message\" name=\"Message\" cols=\"100%\" rows=\"4\" ></textarea>
    <input type=\"submit\" name=\"submit\" id=\"send\" value=\"Send\" />
    </form>


    What am i doing wrong:
  • You do not have a method attribute in your form tag. Add method="post" to your form.
  • thanks box, i knew i had missed something simple.