How to create a form in a web page with HTML

Posted on 2008-11-15
Last Modified: 2012-05-05
I want to create a web page in which a form allows the user to insert some personal informations (name surname, phone, etc.) and send them to me in my email box (see
How is it possible with HTML?
Question by:Sar1973
    LVL 15

    Expert Comment

    The easiest way is set the action of the form as your email address like
    <form method="post" 
    <input type=text 
    <input type=submit 
       value="Submit Your Comments">

    Open in new window

    LVL 10

    Accepted Solution

    The above will open a new email windows for the user, I have attached some code for a form.html file and a php mailer script, although they look messy they work!

    Hope they work for you!
    #HTML FILE...
    <form method="POST" action="mailer.php">
              <table border="0" ALIGN="CENTER" cellpadding="5" cellspacing="0" align="center" style="font-family: Tahoma; font-size: 9pt;">
              <td align="left">Your Name:</td>
              <td align="left" valign="middle"><input type="text" name="name" size="35" style='width: 300px;'>
              <td  align="left">Your
              Email Address:</font></td>
              <td  align="left" valign="middle"> <input type="text" name="email" size="35" style='width: 300px;'>
              <td  align="left">Subject:</font></td>
              <td  align="left" valign="middle"> <input type="text" name="message_subject" size="35" style='width: 300px;'>
              <td  align="left" valign="top">Your
              <td  align="left" valign="top"><textarea name="message" cols="30" rows="8" wrap="VIRTUAL" style='width: 300px;'></textarea>
              <td colspan=2 align=center valign=middle><input type="submit" value="Submit" name="submit">
    if(isset($_POST['submit'])) {
    $to = "";
    $subject = "Contact from website";
    $from = "";
    $name_field = $_POST['name'];
    $email_field = $_POST['email'];
    $message = $_POST['message'];
    $message_subject = $_POST['message_subject'];
    $body = " From: $name_field\n E-Mail: $email_field\n Subject: $message_subject\n Message: $message";
    echo "Data has been submitted successfully.";
    mail($to, $subject, $body);
    } else {
    echo "Sending failed, please check all fields";

    Open in new window

    LVL 9

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 for Beginning Beginners

    Are you looking for an efficient introduction to HTML5? Have you tried other HTML5 courses and found them too complex? Do you need just the basics of HTML5 to use with Wordpress or other content management system? If you said yes to any of these questions, this course is for you.

    Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now