Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP forum question

Options
  • 26-03-2007 10:15pm
    #1
    Closed Accounts Posts: 216 ✭✭


    Hi,

    I'm just trying to get a PHP forum to work on a site, quite new to php. With IE the forum looks fine but when I click submit I get a page not found error, in Firefox the page just shows the php code.

    Is there something obvious wrong with the code or is it the server ?

    Thanks

    (I am running this from a server with PHP)



    <div class="form">

    <?php

    /**
    * $empty_fields_message and $thankyou_message can be changed
    * if you wish.
    */

    // Change to your own email address
    $your_email = "mail@mailserver.ie";

    // This is what is displayed in the email subject line
    // Change it if you want
    $subject = "Message via your contact form";

    // 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>Thankyou. Your message has been sent.</p>";

    // You do not need to edit below this line

    $name = stripslashes($_POST);
    $email = stripslashes($_POST);
    $message = stripslashes($_POST);

    if (!isset($_POST)) {

    ?>
    <form method="post" action="<?php echo $_SERVER; ?>">

    <p><label for="txtName">Name:</label><br />
    <input type="text" title="Enter your name" name="txtName" /></p>

    <p><label for="txtEmail">Email Address:</label><br />
    <input type="text" title="Enter your email address" name="txtEmail" /></p>

    <p>
    <label for="txtMessage">Your Query:</label><br />
    <textarea title="Enter your message" name="txtMessage"></textarea></p>

    <p><label title="Send your message">
    <input type="submit" value="Send" /></label></p>
    </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;
    // Get the URL of this page
    $this_url = "http://".$_SERVER.$_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: $name <$email>");

    // Display the thankyou message
    echo $thankyou_message;

    }

    ?>
    </div>


Comments

  • Moderators, Politics Moderators Posts: 39,920 Mod ✭✭✭✭Seth Brundle


    should
    <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
    
    be
    $HTTP_SERVER_VARS["HTTP_HOST"] . $HTTP_SERVER_VARS["REQUEST_URI"]
    


  • Closed Accounts Posts: 216 ✭✭delanest


    Em, no idea to be honest, I will give it a go later to see, cheers


  • Closed Accounts Posts: 216 ✭✭delanest


    Na I tried this, no luck, would anyone have a script that could be used for a simple submission forum to e-mail,

    thanks ..


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    Are you sure you can run php on your server?


  • Closed Accounts Posts: 216 ✭✭delanest


    Yea I can. It's just an error with the code above ?? - still not sure what it is.

    I've decided to learn a bit of PHP to help with this kind of stuff.

    www.w3schools.com has a good beginners tutorial including an example e-mail submit forum if anybody else wants to check it out


  • Advertisement
  • Closed Accounts Posts: 1,200 ✭✭✭louie


    try this and if you get an error tell us what it says:
    [php]
    <div class="form">

    <?php

    /**
    * $empty_fields_message and $thankyou_message can be changed
    * if you wish.
    */

    // Change to your own email address
    $your_email = "mail@mailserver.ie";

    // This is what is displayed in the email subject line
    // Change it if you want
    $subject = "Message via your contact form";

    // 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>Thankyou. Your message has been sent.</p>";

    // You do not need to edit below this line
    //set variable
    $name = "";
    $email = "";
    $message = "";
    if(isset($_POST) && $_POST != ""){
    $name = stripslashes($_POST);
    }
    if(isset($_POST) && $_POST != ""){
    $email = stripslashes($_POST);
    }
    if(isset($_POST) && $_POST != ""){
    $message = stripslashes($_POST);
    }

    if (!isset($_POST)) {

    ?>
    <form method="post" action="<?php echo $_SERVER; ?>">

    <p><label for="txtName">Name:</label><br />
    <input type="text" title="Enter your name" name="txtName" /></p>

    <p><label for="txtEmail">Email Address:</label><br />
    <input type="text" title="Enter your email address" name="txtEmail" /></p>

    <p>
    <label for="txtMessage">Your Query:</label><br />
    <textarea title="Enter your message" name="txtMessage"></textarea></p>

    <p><label title="Send your message">
    <input type="submit" value="Send" /></label></p>
    </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;
    // Get the URL of this page
    $this_url = "http://".$_SERVER.$_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: $name <$email>");

    // Display the thankyou message
    echo $thankyou_message;

    }

    ?>
    </div>
    [/php]


Advertisement