[PHP] Simple 'contact' form

Discussion in 'Web Programming' started by World Domination, Nov 23, 2010.

[PHP] Simple 'contact' form
  1. Unread #1 - Nov 23, 2010 at 4:02 PM
  2. World Domination
    Joined:
    Apr 9, 2007
    Posts:
    1,563
    Referrals:
    3
    Sythe Gold:
    5

    World Domination Guru
    Banned

    [PHP] Simple 'contact' form

    This is a really simple contact form designed to be put on your website so a user can contact you easily.

    You'll need to create 2 files; and .html and a .php file named contactform.html and ************, respectively.

    Use the following HTML code in your .html file:
    Code:
    <form method="POST" action="************">
       <p>Your Name:<br>
         <input type="text" name="name" size="19" />
         <br />
         Your Email Address:<br>
         <input type="text" name="email" size="19">
      </p>
       <p>
         <select  size="1"  name="subject" id="subject">
    <option>Business</option>
    <option>Site Issue</option>
    <option>Personal</option>
    <option>Other</option>
    </select>
         <br />
        <br>
          Message:<br>
           <textarea rows="9" name="message" cols="30"></textarea>
          <br>
          <br>
          <input type="submit" value="Submit" name="submit">
          </p>
    </form>
    and use the following PHP code in your ************ file:
    PHP:
    <?php

    if(isset($_POST['submit'])) {

    //Change "YOUR_EMAIL_ADDRESS" to the email you want the messages ent to.
    $to "YOUR_EMAIL_ADDRESS";
    $subject $_POST['subject'];
    $name_field $_POST['name'];
    $email_field $_POST['email'];
    $message $_POST['message'];
     
    $body "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
     
    echo 
    "Message sent to $to";
    mail($to$subject$body);

    } else {

    echo 
    "Email not sent, try again.";

    }
    ?>
    A couple notes:
    - be sure to change the Value of the $to variable to your email address you want the script to send the emails to.
    - You can add/remove/change the drop down options of the subject by editing the HTML.

    Edit:
    I forgot to mention, you host must have the "SendMail" function set in the php.ini file, or this won't work.

    Edit2:
    Errr, the "************" above should be contact [dot] php, I'm not sure why it filtered this.
     
  3. Unread #2 - Nov 23, 2010 at 4:12 PM
  4. Ikr
    Joined:
    Nov 23, 2010
    Posts:
    165
    Referrals:
    0
    Sythe Gold:
    0

    Ikr Active Member
    Banned

    [PHP] Simple 'contact' form

    Epic fail with the censors, other than that nice.

    Bookmarking this for future reference. :)
     
< HTML/XHTML Book? | Need help on wordpress >

Users viewing this thread
1 guest


 
 
Adblock breaks this site