Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 8 of 8

Thread: form mail?

  1. #1
    Member
    Join Date
    Aug 2006
    Posts
    67
    Member #
    13752
    Hi!
    I would like to set up a simple contact form on my website. Can someone please sugguest the best way to go about this?

    thanks.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    This is probably the most discussed topic on this forum ... (search for it) ...

    Create a form on your HTML page ...

    The form tag might something look like this:
    <form action="sendit.php" method="post">

    Once you have the form made, give us a link to your page.

    There are a couple of ways to do form validation, where you check
    to make sure the email address is typed in the right format, etc.
    Javascripting I think is best for validation, plus a bit of PHP checking
    for extra security issues.

    You might just want to search Google for: PHP contact form

    You'll probably get example scripts much faster than on this forum.


  4. #3
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    I'm sure I posted a pseudo-tutorial for that.
    Let me find it for you.

    EDIT: Found it! It was originally a comments script, but then again its also a contact form, just the fact that only you get to see the page with the comments.


    blah

    You need to make a database. MySQL is the most common, so I'll use that. If you have phpmyadmin, do an Import to your database with this text:
    Code:
    CREATE TABLE `comments` (
    `name` VARCHAR( 50 ) NOT NULL ,
    `email` VARCHAR( 50 ) NOT NULL ,
    `comment` LONGTEXT NOT NULL
    )
    If you've never used databases before, you need to make a new one. Phpmyadmin makes that easy, although your host may require you to make one in a different manner.

    You need to create a form in HTML, and link it to a php file. The form is just a simple one. Err... I don't have my web tools here, but here's a form: (can be any filename)

    Code:
    <form action="comments_add.php" method="post" name="FormName">
    <label for="name">Name:</label>
            <br />
            <input type="text" name="name" size="50" />
            <br />
            <label for="email"> Email:</label>
            <br />
            <input type="text" name="email size="50" />
            <br />
            <label for="questions">Question or Comment:</label>
            <br />
            <textarea name="comment" rows="10" cols="50"></textarea>
            <br />
    </form>
    Alright. Now, we create the comments_add.php file. To simplify things, here goes... (by the way, we're using PHP superglobals here, introduced near PHP4)
    PHP Code:
    // Connect to mySQL
    $link mysql_connect('localhost''root'''); // <-- MODIFY!!
    mysql_select_db("inserthere"); // <-- MODIFY!!

    // Now we gather info from the form...
    $cName $_POST['name'];
    $cEmail $_POST['email'];
    $cComment $_POST['comment'];

    // Validation
    if(!get_magic_quotes_gpc()){
    $cName mysql_escape_string($cName);
    $cEmail mysql_escape_string($cEmail);
    $cComment mysql_escape_string($cComment);
    }

    // Compact our data into the mySQL query
    $query "INSERT INTO `comments` ( `name` , `email` , `comment` )
    VALUES ('
    $cName', '$cEmail', '$cComment'
    );"

    // Do the query
    mysql_query($query);

    // Go back.
    header("Location: comments.php"); 
    There. Now lets make a page to show the comments... (comments.php)
    PHP Code:

    $link 
    mysql_connect('localhost''root'''); // <-- MODIFY!!
    mysql_select_db("inserthere"); // <-- MODIFY!!

    $query "SELECT * FROM `comments`"// This can be modified to show limits...
    $result mysql_query($query);

    $num mysql_numrows($result);

    for(
    $i=0;$i<$num;$i++){
        
    $uName  mysql_result($result,$i,"name");
        
    $uEmail  mysql_result($result,$i,"email");
        
    $uComment  mysql_result($result,$i,"comment");
        echo 
    "<b>$uName</b> said <blockquote>$uComment</blockquote>"// <-- You can modify this

    EOF

    blah

    Well this is probably the simplest version you can find. It might be a bit rusty because I made this a while ago and there might be better methods. But it works.
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  5. #4
    Senior Member Karloff's Avatar
    Join Date
    Oct 2005
    Posts
    744
    Member #
    11702
    http://www.php-mysql-tutorial.com/fo...n-with-php.php

    there is a very simple mail form with validation

  6. #5
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    I personally don't suggest using an auto-mail form for contact purposes. If you store them in a database instead, you'll have more options, like searching for messages from a certain person, filtering messages that are too short, etc at any time.
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  7. #6
    Junior Member
    Join Date
    Jun 2007
    Posts
    10
    Member #
    15351
    I already have a contact form setup but Iwould like to jazz up the response page (the one that says "thank you, your email has been submitted etc.) by adding a picture.
    How would I do that?

  8. #7
    Senior Member Steax's Avatar
    Join Date
    Dec 2006
    Location
    Bandung, Indonesia
    Posts
    1,207
    Member #
    14572
    Most likely there is a HTML page that says that. Just find it and insert the image normally.
    Note on code: If I give code, please note that it is simply sample code to demonstrate an effect. It is not meant to be used as-is; that is the programmer's job. I am not responsible to give you support or be held liable for anything that happens when using my code.

  9. #8
    Junior Member
    Join Date
    Jun 2007
    Posts
    10
    Member #
    15351
    Quote Originally Posted by Steax
    Most likely there is a HTML page that says that. Just find it and insert the image normally.
    I was up half the night and finally found that page and did insert the image but thanks for the quick response.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:01 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com