www.webdeveloper.com
Results 1 to 9 of 9

Thread: Err. A problem!

  1. #1
    Join Date
    Jun 2011
    Posts
    64

    Question Err. A problem!

    Hi,

    I have a contact form on my site with a seperate PHP script etc.

    But when I submit the form (locally because the site isn't hosted anywhere) it comes up with a bunch of code with the actual page right at the bottom!

    Code:
    <?php
    
    error_reporting(E_ALL ^ E_NOTICE);
    
    /*
    
    Thank you for choosing FormToEmail by FormToEmail.com
    
    Version 2.5 April 16th 2009
    
    COPYRIGHT FormToEmail.com 2003 - 2009
    
    You are not permitted to sell this script, but you can use it, copy it or distribute it, providing that you do not delete this copyright notice, and you do not remove any reference or links to FormToEmail.com
    
    Step 1:
    
    To put the form on your webpage, copy the code below as it is, and paste it into your webpage:
    
    <form action="FormToEmail.php" method="post">
    <table border="0" style="background:#ececec" cellspacing="5">
    <tr align="left"><td>Name</td><td><input type="text" size="30" name="name"></td></tr>
    <tr align="left"><td>Email address</td><td><input type="text" size="30" name="email"></td></tr>
    <tr align="left"><td valign="top">Comments</td><td><textarea name="comments" rows="6" cols="30"></textarea></td></tr>
    <tr align="left"><td>&nbsp;</td><td><input type="submit" value="Send"><font face="arial" size="1">&nbsp;&nbsp;<a href="http://FormToEmail.com">PHP Form</a> by FormToEmail.com</font></td></tr>
    </table>
    </form>
    
    Step 2:
    
    Enter your email address.
    
    Enter the email address below to send the contents of the form to.  You can enter more than one email address separated by commas, like so: $my_email = "info@example.com"; or $my_email = "bob@example.com,sales@example.co.uk,jane@example.com";
    
    */
    
    $my_email = "thomas.hochkins@tiscali.co.uk";
    
    /*
    
    Optional.  Enter a From: email address.  Only do this if you know you need to.  By default, the email you get from the script will show the visitor's email address as the From: address.  In most cases this is desirable.  On the majority of setups this won't be a problem but a minority of hosts insist that the From: address must be from a domain on the server.  For example, if you have the domain example.com hosted on your server, then the From: email address must be something@example.com (See your host for confirmation).  This means that your visitor's email address will not show as the From: address, and if you hit "Reply" to the email from the script, you will not be replying to your visitor.  You can get around this by hard-coding a From: address into the script using the configuration option below.  Enabling this option means that the visitor's email address goes into a Reply-To: header, which means you can hit "Reply" to respond to the visitor in the conventional way.  (You can also use this option if your form does not collect an email address from the visitor, such as a survey, for example, and a From: address is required by your email server.)  The default value is: $from_email = "";  Enter the desired email address between the quotes, like this example: $from_email = "contact@example.com";  In these cases, it is not uncommon for the From: ($from_email) address to be the same as the To: ($my_email) address, which on the face of it appears somewhat goofy, but that's what some hosts require.
    
    */
    
    $from_email = "";
    
    /*
    
    Optional.  Enter the continue link to offer the user after the form is sent.  If you do not change this, your visitor will be given a continue link to your homepage.
    
    If you do change it, remove the "/" symbol below and replace with the name of the page to link to, eg: "mypage.htm" or "http://www.elsewhere.com/page.htm"
    
    */
    
    $continue = "/";
    
    /*
    
    Step 3:
    
    Save this file (FormToEmail.php) and upload it together with your webpage containing the form to your webspace.  IMPORTANT - The file name is case sensitive!  You must save it exactly as it is named above!
    
    THAT'S IT, FINISHED!
    
    You do not need to make any changes below this line.
    
    */
    
    $errors = array();
    
    // Remove $_COOKIE elements from $_REQUEST.
    
    if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
    
    // Validate email field.
    
    if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
    {
    
    $_REQUEST['email'] = trim($_REQUEST['email']);
    
    if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ") || stristr($_REQUEST['email'],"\\") || stristr($_REQUEST['email'],":")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}
    
    }
    
    // Check referrer is from same site.
    
    if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}
    
    // Check for a blank form.
    
    function recursive_array_check_blank($element_value)
    {
    
    global $set;
    
    if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
    else
    {
    
    foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}
    
    }
    
    }
    
    recursive_array_check_blank($_REQUEST);
    
    if(!$set){$errors[] = "You cannot send a blank form";}
    
    unset($set);
    
    // Display any errors and exit if errors exist.
    
    if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
    
    if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}
    
    // Build message.
    
    function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
    
    $message = build_message($_REQUEST);
    
    $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you for using FormToEmail from http://FormToEmail.com";
    
    $message = stripslashes($message);
    
    $subject = "FormToEmail Comments";
    
    $subject = stripslashes($subject);
    
    if($from_email)
    {
    
    $headers = "From: " . $from_email;
    $headers .= PHP_EOL;
    $headers .= "Reply-To: " . $_REQUEST['email'];
    
    }
    else
    {
    
    $from_name = "";
    
    if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}
    
    $headers = "From: {$from_name} <{$_REQUEST['email']}>";
    
    }
    
    mail($my_email,$subject,$message,$headers);
    
    ?>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    
    <head>
    <title>Form To Email PHP script from FormToEmail.com</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link href="stylesheet.css" rel="stylesheet" type="text/css">
    </head>
    
    <body bgcolor="#bfbfbf" text="#000000">
    
    <div id="contact">
    <center>
    <b id="thankyou">Thank you <?php if(isset($_REQUEST['name'])){print stripslashes($_REQUEST['name']);} ?></b>
    <br><p>Your message has been sent</p>
    <p><a href="index.html">Click here if you are not automatically redirected</a></p>
    <p><b>FormToEmail</b> by <a href="http://FormToEmail.com">FormToEmail.com</a></p>
    </center>
    </div>
    
    </body>
    </html>

    What is the problem and how do I fix it?

    Thanks
    Thomas

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    Have you installed a web server (e.g. Apache) and PHP on your local machine where you're testing it? (If not, look into Wampserver [windows only] or XAMPP [many platforms] to install everything you need.)

    If you are running a web server and PHP already, then make sure you open the form page via a localhost URL, not by a "file://" URL or double-clicking the file (e.g.: "http://localhost/form_page.html" or whatever it's called), so that the form will be submitted via the web server, too, thus invoking the PHP parser/compiler.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jun 2011
    Posts
    64

    Cool Thanks

    Thanks for you help.

    So if I install Wampserver and then re-run the contact for an the script then it should work even though the site isn't on a server?


    Thanks
    Thomas

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    Yes, it will, in effect, be on a server at that point. It just won't be accessible to the outside world (i.e. the web); but you'll be running a local web server essentially the same as any web site.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jun 2011
    Posts
    64

    Unhappy Hmmm....?

    Thanks for your reply,

    When I installed wampserver and ran the form again using the 'preview in a browser' within dreamweaver it did the same thing?


    Do you know any other free mail scripts? Or anywhere that has easy steps on how to make one?

    It probably doesn't help that I know nothing about PHP!


    Thanks
    Thomas

  6. #6
    Join Date
    May 2011
    Posts
    101
    Quote Originally Posted by TomTom100 View Post
    When I installed wampserver and ran the form again using the 'preview in a browser' within dreamweaver it did the same thing?
    Yes, it would do that !
    Previewing a page in a browser from most tools like DW, simply lets
    you *see* what your HTML might look like. It takes no account of whether
    you want the file parsed as a script.
    -
    NogDog is (as seems usual !) spot-on the money.
    You HAVE to serve the file to have it execute as a script.
    Not sure what the Windows options are for this but Macs come replete
    with a full-on Apache 2.2 server, which makes my development life
    a zillion times easier. Windows users will advise you, I'm sure.

    Quote Originally Posted by TomTom100 View Post
    Do you know any other free mail scripts? Or anywhere that has easy steps on how to make one?
    PM me, and I'll send you the one I use all the time.

    Quote Originally Posted by TomTom100 View Post
    It probably doesn't help that I know nothing about PHP!
    There is no shame in being a learner.
    For as long as we remain conscious, we are all learning.

    Chris

  7. #7
    Join Date
    Jun 2011
    Posts
    64

    Question Thanks

    Thanks for all your help!

    How would I run my site through Wampserver?


    Thanks
    Thomas

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    Make sure the files are in the "www" directory (or one of its sub-directories) under your Wampserver installation, typically something like "C:\wamp\www\". Then to run it, open your browser, and use a URL in the format "http://localhost/your_file_name.php". Oh, and don't forget to launch Wampserver first (you should have a little semicircular icon (like an instrument dial) in the part of your Windoze status bar where it shows network status, speaker volume, etc.).
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Jun 2011
    Posts
    64

    Unhappy Ahhh!!

    Help!!!!


    Nothing is seemin to be working! I don't really understand how to use wampserver or anything to do with PHP


    Thanks for your help though!

    I'll probably get someone to do it for me, i'll just start another thread then




    Thanks
    Thomas

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles