Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

PHP forum question

  • 26-03-2007 09:15PM
    #1
    Closed Accounts Posts: 206 ✭✭


    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, Paid Member Posts: 44,344 Mod ✭✭✭✭Seth Brundle


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

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Closed Accounts Posts: 206 ✭✭delanest


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


  • Closed Accounts Posts: 206 ✭✭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: 206 ✭✭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