"Contact Us" Form Scripts

Discussion in 'Programming' started by pearz76, Nov 20, 2005.

  1. #1
    Hi guys,

    I need help in getting a script for my Contact Us page and the testimonials page.

    I quite bad in php and asp. Is there any simple code or tutorials in the webs that I follow thru the steps?

    I had been looking around the web for quite sometimes but to no avail.

    TKs.
     
    pearz76, Nov 20, 2005 IP
  2. mdvaldosta

    mdvaldosta Peon

    Messages:
    4,079
    Likes Received:
    362
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've got a good script, lemme get the php file for you.

    You can see it here:

    http://www.moddedmustangs.com/contact-us/

    edit - here is the code. replace the stuff I changed for your email address, message, etc. and the color style for the boxes (I run a dark theme - just remove the style="000000" stuff). All you gotta do is call it with a php includes, or put this in your php file.

    <?php
    
    /**
     * Change the email address to your own.
     *
     * $empty_fields_message and $thankyou_message can be changed
     * if you wish.
     */
    
    // Change to your own email address
    $your_email = "Insert Email Address";
    
    // This is what is displayed in the email subject line
    // Change it if you want
    $subject = "Contacting Insert Site Name";
    
    // This is displayed if all the fields are not filled in
    $empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>";
    
    // This is displayed when the email has been sent
    $thankyou_message = "<p>Insert your Thank you Message</p>";
    
    // You do not need to edit below this line
    
    $name = stripslashes($_POST['txtName']);
    $email = stripslashes($_POST['txtEmail']);
    $message = stripslashes($_POST['txtMessage']);
    
    if (!isset($_POST['txtName'])) {
    
    ?>
    
    <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
    
        <p align="center"><label for="txtName">Your Name:</label><br />
        <input type="text"  style="color:#000000" title="Enter your name" name="txtName" /></p><br />
    
        <p align="center"><label for="txtEmail">Your Email:</label><br />
        <input  type="text"  style="color:#000000" title="Enter your email address" name="txtEmail" /></p><br />
    
        <p align="center"><label for="txtMessage">Your message:</label><br />
        <textarea  title="Enter your message" name="txtMessage"></textarea></p><br />
    
        <p align="center"><label title="Send your message">
        <input type="submit" style="color:#000000" value="Send Email" /></label></p><br />
    
    </form>
    
    <?php
    
    }
    
    elseif (empty($name) || empty($email) || empty($message)) {
    
        echo $empty_fields_message;
    
    }
    
    else {
    
        // Stop the form being used from an external URL
        // Get the referring URL
        $referer = $_SERVER['HTTP_REFERER'];
        // Get the URL of this page
        $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
        // If the referring URL and the URL of this page don't match then
        // display a message and don't send the email.
        if ($referer != $this_url) {
            echo "You do not have permission to use this script from another URL, nice hacking attempt moron.";
            exit;
        }
    
        // The URLs matched so send the email
        mail($your_email, $subject, $message, "From: $name <$email>");
    
        // Display the thankyou message
        echo $thankyou_message;
        
    }
    
    ?>
    Code (markup):
     
    mdvaldosta, Nov 20, 2005 IP
  3. pearz76

    pearz76 Peon

    Messages:
    521
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi mdvaldosta ,

    Tks. do get me the script.
     
    pearz76, Nov 20, 2005 IP
  4. mdvaldosta

    mdvaldosta Peon

    Messages:
    4,079
    Likes Received:
    362
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I just edited my post above and put it in. If you need any help getting it going just ask. It's simple though, I just put it in another file and called it with an includes.
     
    mdvaldosta, Nov 20, 2005 IP
  5. pearz76

    pearz76 Peon

    Messages:
    521
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    mdvaldosta,

    Do I have to make 2 separate asp file for 'contact us' and 'testimonials' page? Do I have to combine it to my HTML page ?
     
    pearz76, Nov 20, 2005 IP
  6. pearz76

    pearz76 Peon

    Messages:
    521
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Below is the code.Extract from my website. Do I combine the PHP code that you shown me with my table below?

    <form action="" method="post" name="form" id="form">
    <table width="90%" border="0" cellspacing="2" cellpadding="4">
    <tr>
    <td width="10%" align="right" valign="top">Name:</td>
    <td colspan="2" valign="top"><input name="name" type="text" id="name" size="30">
    </td>
    </tr>
    <tr>
    <td width="10%" align="right" valign="top">Email:</td>
    <td colspan="2" valign="top"><input name="email" type="text" id="email" size="30">
    </td>
    </tr>
    <tr>
    <td width="10%" align="right" valign="top">Subject:</td>
    <td colspan="2" valign="top"><input name="subject" type="text" id="subject" size="30">
    </td>
    </tr>
    <tr>
    <td valign="top" align="right" width="10%">Message:</td>
    <td colspan="2" valign="top"><textarea name="message" cols="30" rows="5" id="message"></textarea>
    </td>
    </tr>
    <tr>
    <td width="10%" align="right">&nbsp;</td>
    <td colspan="2"><input type="submit" name="Submit" value="Send">
    </td>
    </tr>
    </table>
    </form>
     
    pearz76, Nov 21, 2005 IP
  7. Mr.Rock

    Mr.Rock Peon

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #7
    hey I can provide you a nice Contact Us forum :) in that form when some1 will send you a msg the sender will receive a thank you email & lot more in that form, if u need it plz send me PM. if u want t creat your own & simple form plz log in to this site for FREE and set all fields according to ur own choice!

    http: // www . hotwebtools . com / form_gen
    (plz remove space befre visiting it as i am new & not allowed Live links
    enjoy :p

    Mr Rock :)
     
    Mr.Rock, Jul 8, 2006 IP