• home
  • forum
  • my
  • kt
  • download
  • Simple Contact Form Using PHP

    Author: 2008-08-24 10:05:41 From:

    Thought I'd share on how to put a form on your website that people can fill in and send you an email without them having to see your email or open a client.

    It's VERY basic and doesn't have any error handling which I need to get around to doing.

    ---

    1. Open your scripting program (Notepad, Context, Dreamweaver).

    2. Insert the following code:

    CODE

    <?php
    $to = "youremail@yourisp.com";
    $sub = "Subject of the Email Here";
    ?>


    3. Make sure no other code is in that file. If you used Dreamweaver or a similar editor make sure you remove the excess tags. Replace the two parts within the quote marks to reflect your settings. Mine is:

    CODE

    <?php
    $to = "spikeh@spikeh.com";
    $sub = "Spikeh.com Contact Email";
    ?>


    4. Save this file as "config.php"

    5. Open the page that you want to add the contact form to.

    6. Insert this code exactly where you want the form to appear:

    CODE

    <?php
    include ("config.php");
    ?>
    <form action="contact.php" mehod="post">
    Your Email Address:<br>
    <input type="text" name="useraddr" size="30">
    <br>
    Message:<br>
    <textarea name="comments" cols="50" rows="7"> </textarea>
    <br>
    <br>
    <input type="submit" value="Send Form"> <input name="Reset" type="reset" value="Reset">
    </form>
    <?php
    if (isset($comments)) {
    $msg = $comments;
    $from = "From: $useraddr";
    // $msg .= "You may contact the sender at the following email address: $useraddr";
    mail($to,$sub,$msg,$from);
    echo "Your message has been sent.";
    }
    ?>


    7. You then need to save this file with a .php extension. If the file was origionally "contact.htm" then it now needs to be "contact.php" or the php section just won't work.

    8. Upload the config.php file and the contact.php file to your site and test it out.

    ---

    I hope people find this useful. If anyone would like to build upon this and make it better then please do by all means. Just let me know what you did and give me a copy of the code.

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (11)
      Guestbooks (12)
      Image Manipulation (21)
      Installing PHP (7)
      Introduction to PHP (24)
      Link Indexing (8)
      Mailing List Management (9)
      Miscellaneous (54)
      Networking (8)
      News Publishing (9)
      OOP (24)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (6)
      Postcards (1)
      Randomizing (14)
      Redirection (11)
      Searching (9)
      Security (29)
      Site Navigation (16)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot