Need a simple contact form script

Discussion in 'Programming' started by midlandi, Nov 9, 2007.

Remove these ads by signing in
Remove these ads by signing in
Thread Status:
Not open for further replies.
  1. midlandi Can you smell that?

    Member Since:
    Jan 22, 2007
    Message Count:
    4,758
    Likes Received:
    33
    Location:
    Uk
    Need a simple contact form script, the one I have seems to have a bug.
  2. ST-Mike TriPHP Contributor

    Member Since:
    Oct 18, 2007
    Message Count:
    387
    Likes Received:
    13
    Location:
    Liverpool, UK
    What language?

    I can sort one in PHP later on but not at the moment.

    In essence though it's really simple, just use of the PHP mail() function (type that into google for more info) and sending the info from a form with $_POST etc. However, try and remember to check data being inputted first etc! Perhaps you'll be able to sort this yourself if you have any knowledge of PHP?
  3. midlandi Can you smell that?

    Member Since:
    Jan 22, 2007
    Message Count:
    4,758
    Likes Received:
    33
    Location:
    Uk
    I could do my own I just have zero time, so looking for quick fix for now.
    Its for the site villawithapool.co.uk , so i can remove the email link.
  4. ST-Mike TriPHP Contributor

    Member Since:
    Oct 18, 2007
    Message Count:
    387
    Likes Received:
    13
    Location:
    Liverpool, UK
    A VERY simple contact form:

    PHP:

    <?php
    if(isset($_POST['message'])) {
    mail(website.owner@domain.com,"Feedback from website",$_POST['message']);
    echo "Message sent.";
    }
    ?>
     
    Code (text):

    <form name="contactFrm" action="this_page.php" method="POST">
    <textarea name="message">Typr your message here.</textarea><br />
    <input type="submit" value="Send" />
    </form>
     
    Again, I must stress this is very simple. You should record the users IP Address etc and also put something like a captcha image in to prevent spamming and automatic submission.
    1 people like this.
  5. midlandi Can you smell that?

    Member Since:
    Jan 22, 2007
    Message Count:
    4,758
    Likes Received:
    33
    Location:
    Uk
  6. ST-Mike TriPHP Contributor

    Member Since:
    Oct 18, 2007
    Message Count:
    387
    Likes Received:
    13
    Location:
    Liverpool, UK
    No problemo! Even without a captcha code, if the form begins to get automatic spam and submissions, then it's a simple case of banning the IP Address. Plus the form is only sending e-mail to the website owners address, so it cannot be abused too much!

    A nice touch could be asking for the visitors name to send along with the message (another input box). Also note that you should ask for their e-mail address so that you can reply! The above example will not send the e-mail from their address either - so as a quick remedy just ask them to include their e-mail address in the message, when replying you will have to copy and paste this because the reply address will be back to the server the original e-mail was sent from :p
  7. ST-Mike TriPHP Contributor

    Member Since:
    Oct 18, 2007
    Message Count:
    387
    Likes Received:
    13
    Location:
    Liverpool, UK
    Heres another, slightly better, contact form that somebody added as a comment at PHP.net.

    PHP:

    <?php
    if (isset($_REQUEST['email']))
    //if "email" is filled out, send email
      {
      //send email
      $email = $_REQUEST['email'] ;
      $subject = $_REQUEST['subject'] ;
      $message = $_REQUEST['message'] ;
      mail( "someone@example.com", "Subject: $subject",
      $message, "From: $email" );
      echo "Thank you for using our mail form";
      }
    else
    //if "email" is not filled out, display the form
      {
      echo "<form method='post' action='mailform.php'>
      Email: <input name='email' type='text' /><br />
      Subject: <input name='subject' type='text' /><br />
      Message:<br />
      <textarea name='message' rows='15' cols='40'>
      </textarea><br />
      <input type='submit' />
      </form>"
    ;
      }
    ?>
     
    This will also just show "message sent" with no contact form once it has been submitted. Again, a fairly simple example but I think it will be fine :)
  8. AcesHigh New Member

    Member Since:
    Aug 15, 2007
    Message Count:
    197
    Likes Received:
    0
    wow your good, i might have to steal that code incase i need it someday XD
  9. route66 New Member

    Member Since:
    Jan 30, 2007
    Message Count:
    84
    Likes Received:
    0
    Nice....Just what i need. Thanks for sharing.
  10. ST-Mike TriPHP Contributor

    Member Since:
    Oct 18, 2007
    Message Count:
    387
    Likes Received:
    13
    Location:
    Liverpool, UK
    Heh, if you develop websites and are ready to take it to the next step - I highly recommend learning a server-side programming language to create more dynamic websites. You can do wonders with the likes of PHP and in particular PHP is very popular - once you've got your heard around the way the language works it's very easy to learn new things.
  11. detoam New Member

    Member Since:
    Apr 29, 2007
    Message Count:
    387
    Likes Received:
    8
    Occupation:
    webmaster
    Location:
    Canada
    I use coffeecups form builder. Highly customizable and simple to use.
  12. Indigo New Member

    Member Since:
    Jul 18, 2007
    Message Count:
    194
    Likes Received:
    0
    Can I use this code on blogger?
  13. ST-Mike TriPHP Contributor

    Member Since:
    Oct 18, 2007
    Message Count:
    387
    Likes Received:
    13
    Location:
    Liverpool, UK
    Nope, I don't think. Blogger looks after all of your code, don't they? I.e., they host the blog unless you use the FTP option.

    You *could* use it if you hosted the contact PHP script elsewhere and had the form on your blog submitting to it (have the action defined to the URL of the php processing script, which would be elsewhere!)
  14. midlandi Can you smell that?

    Member Since:
    Jan 22, 2007
    Message Count:
    4,758
    Likes Received:
    33
    Location:
    Uk
  15. Indigo New Member

    Member Since:
    Jul 18, 2007
    Message Count:
    194
    Likes Received:
    0
    Oh, ok... anyway, thanks for your response...
    btw midlandi, that's a very handy contact builder tool! :):
  16. grap6b New Member

    Member Since:
    Feb 15, 2008
    Message Count:
    20
    Likes Received:
    0
    hi midlandi,
    after getting the answer from St-mike you might have fixed your problem. I now also you need the help the post a private message to me I will solve out your problem.
Thread Status:
Not open for further replies.

Share This Page