1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Contact Form

Discussion in 'General Programming Chat' started by s-c-0-r-p-i-a-n, Aug 28, 2011.

  1. s-c-0-r-p-i-a-n

    s-c-0-r-p-i-a-n BANNED BANNED

    Joined:
    Nov 20, 2010
    Messages:
    37
    Likes Received:
    2
    Here is code...One part is PHP, one is HTML...

    PHP Code

    Code:
    <?php
    if(isset($_POST['submit'])) {
    
       $to = "mail id"; 
       $subject = "Form Tutorial";
       $name_field = $_POST['name'];
       $email_field = $_POST['email'];
       $message = $_POST['message'];
       $option = $_POST['radio'];
       $dropdown = $_POST['drop_down'];
    
       foreach($_POST['check'] as $value) {
          $check_msg .= "Checked: $value\n";
       }
       
       $body = "From: $name_field\n E-Mail: $email_field\n $check_msg Option: $option\n Drop-Down: $dropdown\n Message:\n $message\n";
    
       echo "Data has been submitted to $to!";
       mail($to, $subject, $body);
       
    } else {
       echo "Error, please try again!";
    }
    ?>
    HTML CODE:

    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>New Page 1</title>
    </head>
    
    <body>
    
    <form method="POST" action="mailer.php">
       Name:
       <input type="text" name="name" size="19"><br>
       <br>
       E-Mail:
       <input type="text" name="email" size="19"><br>
       <br>
       
       <input type="checkbox" name="check[]" value="blue_color"> Blue<br>
       <input type="checkbox" name="check[]" value="green_color"> Green<br>
       <input type="checkbox" name="check[]" value="orange_color"> Orange<br>
       <br>
       <input type="radio" value="yes" name="radio"> YES<br>
       <input type="radio" value="no" name="radio"> NO
       <br>
       <br>
       <select size="1" name="drop_down">
       <option>php</option>
       <option>xml</option>
       <option>asp</option>
       <option>jsp</option>
       </select><br>
       <br>
       Message:<br>
       <textarea rows="9" name="message" cols="30"></textarea><br>
       <br>
       <input type="submit" value="Submit" name="submit">
    </form>
    
    </body>
    
    </html>
     
  2. plumbum416

    plumbum416 Registered Member

    Joined:
    Mar 17, 2011
    Messages:
    96
    Likes Received:
    16
    What about your code? Did you want to ask anything? If yes what? Or is it just pure code as a kind of explanation?
    I don't get why you are just opening a thread stating : here is PHP code, and here is a HTML-site without telling any reason why you posted it
     
  3. licorne101

    licorne101 Registered Member

    Joined:
    Aug 22, 2011
    Messages:
    88
    Likes Received:
    118
    I think he's sharing code which is pretty pointless because it looks very generic and doesn't deal with any security.
     
  4. JohnnyRabbit

    JohnnyRabbit Supreme Member

    Joined:
    Sep 29, 2010
    Messages:
    1,228
    Likes Received:
    299
    Thanks for the share
     
  5. plumbum416

    plumbum416 Registered Member

    Joined:
    Mar 17, 2011
    Messages:
    96
    Likes Received:
    16
    Didn't think about this. Well it is very basic code, but to some newbies it might be helpfull (escpecially for those who do never google anything :D )