Suggestion/email script - does this exist?

Discussion in 'Scripts' started by maney, Nov 11, 2006.

  1. #1
    I'm after something in which I can put a field on my site (just a small field, 100characters max or something) with a send button so users can tell me what they'd like to see on my website. I just want whatever the person puts in the field to be emailed to an adress of my choice.

    Does this script exist?
     
    maney, Nov 11, 2006 IP
  2. hiredgunz

    hiredgunz Peon

    Messages:
    203
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yep .. it exists on millions of websites as an email form :D

    Heres one you can edit to your needs if you are using php pages:

    
    <?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 = "Your Email Address Here";
    
    // This is what is displayed in the email subject line
    // Change it if you want
    $subject = "Suggestion From Your Site";
    
    // 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 = "<br><br><p>Thank you. Your message has been sent to Admin.</p>";
    
    // You do not need to edit below this line
    
    $name = stripslashes($_POST['txtName']);
    $email = ($_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" size="35"/></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" size="35"/></p><br />
    
        <p align="center"><label for="txtMessage">Your message:</label><br />
        <textarea  cols="50" rows="15" 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.";
            exit;
        }
    
        // The URLs matched so send the email
        mail($your_email, $subject, $message, "From: $email");
    
        // Display the thankyou message
        echo $thankyou_message;
        
    }
    ?>
    
    Code (markup):
    Just change the text and paste the code into your php page and it should work for you :)

    best,

    Jan
     
    hiredgunz, Nov 14, 2006 IP
  3. RRWH

    RRWH Active Member

    Messages:
    821
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    70
    #3
    A better option would be to NOT use the above script but use one which is secure!

    The above form could easily be hijacked by spammers as there is absolutely no data validation done on the entered information. The form only checks that you have something in each filed, but it doesn't care what is entered - this is VERY bad!

    Now, if you want to find a much more secure form mail script check out http://www.rrwh.com/scripts.php
     
    RRWH, Nov 16, 2006 IP
  4. hiredgunz

    hiredgunz Peon

    Messages:
    203
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Very true ... the above is not a secure form, but simply an example to show the basics of how it's done :) Guess I should include detailed disclaimers before sharing code in public LoL ..

    best,

    Jan
     
    hiredgunz, Nov 16, 2006 IP