1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

how to write a contact form

Discussion in 'Web Design & Development' started by zombienation, Nov 22, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. zombienation

    zombienation Thread Starter

    Joined:
    Aug 6, 2003
    Messages:
    337
    Hi There I have written a webpage with home, about etc + a contact page

    Now I have written a form for the contact button how can i Direct it to go to my email after i press the submit button

    hopefully somebody can help me out.
     

    Attached Files:

  2. ehymel

    ehymel

    Joined:
    Aug 12, 2007
    Messages:
    696
    Lots of ways to do this on your own, but I have used formmail.php (available here) with success in the past.
     
  3. dojo-kim

    dojo-kim

    Joined:
    Nov 28, 2011
    Messages:
    2
    One possibility is to use two separate files:

    contact.html

    Include this form somewhere in your HTML code.
    HTML:
    <form method="post" action="mailer.php">
    Name:<br/>
    <input type="text" name="name" /><br/>
    Subject:<br/>
    <input type="text" name="subject" /><br/>
    E-Mail:<br/>
    <input type="text" name="email" /><br/>
    Website:<br/>
    <input type="text" name="website" /><br/>
    Message:<br/>
    <textarea id="message" cols="35" rows="5"></textarea><br/>
    <input type="submit" value="Submit!" />
    </form>
    
    mailer.php

    Put this file in the same folder as the contact page.
    PHP:
    // get variables from the post
    $name $_POST['name'];
    $subject $_POST['subject'];
    $email $_POST['email'];
    $website $_POST['website'];
    $message $_POST['message'];
     
    // Your email here
    $to "[email protected]";
     
    // The actual mailer function 
    mail($to,$subject,$message);
    This is just a simple form with a POST method. The php then grabs the HTML form data and puts them into the php mail function. If you want to, you should also add some sort of CAPTCHA to prevent from bots/spam entering your email.
     
  4. ehymel

    ehymel

    Joined:
    Aug 12, 2007
    Messages:
    696
    Why 2 separate files? It's much easier from a maintenance standpoint to have all of this in a single file, then have the form page post to itself. After processing, the php code can redirect to another page (e.g., "Thanks for your submission") or flag fields on the form for further information gathering.
     
  5. dojo-kim

    dojo-kim

    Joined:
    Nov 28, 2011
    Messages:
    2
    Well yes of course, I simply used two files to point out the way forms work...

    contact.php:

    (instead of contact.php, you can use <?php echo $_SERVER['PHP_SELF']; ?>)
    PHP:
    <?php
    if(isset($_POST['submit'])){ 
    // get variables from the post
    $name $_POST['name'];
    $subject $_POST['subject'];
    $email $_POST['email'];
    $website $_POST['website'];
    $message $_POST['message'];
     
    // Your email here
    $to "[email protected]";
     
    // The actual mailer function 
    mail($to,$subject,$message);  
    }
    ?>

    <form method="post" action="contact.php">
    Name:<br/>
    <input type="text" name="name" /><br/>
    Subject:<br/>
    <input type="text" name="subject" /><br/>
    E-Mail:<br/>
    <input type="text" name="email" /><br/>
    Website:<br/>
    <input type="text" name="website" /><br/>
    Message:<br/>
    <textarea id="message" cols="35" rows="5"></textarea><br/>
    <input type='hidden' name='submit' />
    <input type="submit" value="Submit!" />
    </form>
    That should do the trick.
     
  6. buff3r0vrfl0w

    buff3r0vrfl0w

    Joined:
    Feb 7, 2011
    Messages:
    186

    Hey idk if you solved this already but I've been playing with google forms and kinda love the simplicity and easy email notification. Here's a simple tut on how to setup a form to dump to a spreadsheet and notify you via email of new entries.

    http://youtu.be/E5CfuRTy1V4

    just my .2
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - write contact form
  1. howard.a.s
    Replies:
    5
    Views:
    515
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1028058

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice