Can someone make me a contact form?

Discussion in 'PHP' started by prilep, Feb 12, 2010.

  1. #1
    I need a contact form. Very simple. I only need 3 fields:

    name
    type: (i need a drop down type1, 2 and 3)
    message: (text area)

    and a submit button and thats it :). In return free hosting.
     
    prilep, Feb 12, 2010 IP
  2. Richie_Ni

    Richie_Ni Illustrious Member

    Messages:
    10,721
    Likes Received:
    1,175
    Best Answers:
    0
    Trophy Points:
    410
    #2
    Richie_Ni, Feb 12, 2010 IP
  3. prilep

    prilep Well-Known Member

    Messages:
    3,852
    Likes Received:
    228
    Best Answers:
    0
    Trophy Points:
    185
    #3
    Well actually there are very neat generators, but i also need a drop menu. I cant find a generator that does that.

    - prilep :)
     
    prilep, Feb 12, 2010 IP
  4. Richie_Ni

    Richie_Ni Illustrious Member

    Messages:
    10,721
    Likes Received:
    1,175
    Best Answers:
    0
    Trophy Points:
    410
    #4
    Richie_Ni, Feb 12, 2010 IP
  5. prilep

    prilep Well-Known Member

    Messages:
    3,852
    Likes Received:
    228
    Best Answers:
    0
    Trophy Points:
    185
    #5
    Yup I found that also, but no need to pay 7 bucks for something that simple.
     
    prilep, Feb 12, 2010 IP
  6. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #6
    Let me see if I am smart enough to add 3 drop downs to the one I have already written.

    BBL. :)
     
    Colbyt, Feb 12, 2010 IP
  7. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #7
    This forum is for php help, not php demands. If you need it you'd post in the BST and hire someone, or learn php to do it yourself, learning yourself is much more rewarding.

    Untested, but this should work:

    <?php
      function clean($input)
      {
         //basic security function, to prevent spam etc...
          return str_replace(array("content-type", "bcc:", "to:", "cc:", "href"), "", strip_tags($input));
      }
      
      //check if form is submitted, and ALL fields are not empty
      if (isset($_POST['submit']) && !empty($_POST['name']) && !empty($_POST['message']) && !empty($_POST['type'])) {
          
          //your email - where the contact form data will be emailed too...
          $email = "you@domain.com";
          
          $subject = "Contact Form";
          
          $message = "Message: " . clean($_POST['message']) . "\n";
          
          $message .= "Name: " . clean($POST['name']) . "\n";
          
          $message .= "Type: " . clean($POST['type']);
          
          $valid = true;
      }
    ?>
    
    <form method="post">
    
    Name: <br />
    <input type="text" name="name"><br /><br />
    
    Type: <br />
    <select name="type">
      <option value="Type1">Type1</option>
      <option value="Type2">Type2</option>
      <option value="Type3">Type3</option>
    </select><br /><br />
    
    Message:<br />
    <textarea name="message" rows="6" cols="50"></textarea><br /><br />
    
    <input type="submit" name="submit" value="Submit">
    
    </form>
    
    <?php
      if (@$valid == true && mail($email, $subject, $message)) {
          echo "Mail Sent";
      }
    ?>
    PHP:
    I don't need the hosting...
     
    Last edited: Feb 13, 2010
    danx10, Feb 13, 2010 IP
  8. prilep

    prilep Well-Known Member

    Messages:
    3,852
    Likes Received:
    228
    Best Answers:
    0
    Trophy Points:
    185
    #8
    For some reason only the message gets through. The other stuff is just blank.
     
    prilep, Feb 16, 2010 IP
  9. Izonedig

    Izonedig Member

    Messages:
    150
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #9
    Strange, try to not use clean() function, if still problem try to replace
    clean($_POST['message'])
    by
    clean($POST['name'])
    just for one reason: check if you get the name after "Message:" or it is blank, then let me know so I can help you.
     
    Izonedig, Feb 16, 2010 IP
  10. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #10
    Woops typo, use this:

    <?php
      function clean($input)
      {
         //basic security function, to prevent spam etc...
          return str_replace(array("content-type", "bcc:", "to:", "cc:", "href"), "", strip_tags($input));
      }
     
      //check if form is submitted, and ALL fields are not empty
      if (isset($_POST['submit']) && !empty($_POST['name']) && !empty($_POST['message']) && !empty($_POST['type'])) {
         
          //your email - where the contact form data will be emailed too...
          $email = "you@domain.com";
         
          $subject = "Contact Form";
         
          $message = "Message: " . clean($_POST['message']) . "\n";
         
          $message .= "Name: " . clean($_POST['name']) . "\n";
         
          $message .= "Type: " . clean($_POST['type']);
         
          $valid = true;
      }
    ?>
    
    <form method="post">
    
    Name: <br />
    <input type="text" name="name" /><br /><br />
    
    Type: <br />
    <select name="type">
      <option value="Type1">Type1</option>
      <option value="Type2">Type2</option>
      <option value="Type3">Type3</option>
    </select><br /><br />
    
    Message:<br />
    <textarea name="message" rows="6" cols="50"></textarea><br /><br />
    
    <input type="submit" name="submit" value="Submit" />
    
    </form>
    
    <?php
      if (@$valid == true && mail($email, $subject, $message)) {
          echo "Mail Sent";
      }
    ?>
    PHP:
     
    danx10, Feb 16, 2010 IP