Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2009
    Posts
    887
    Thanks
    137
    Thanked 24 Times in 24 Posts

    script not working

    I have this code yet when I complete the form using the local host, on submit, I get all the code instead of the thank you message.

    PHP Code:
    <?php

    // if the url field is empty
    if(isset($_POST['url']) && $_POST['url'] == ''){

        
    $youremail '[email protected];

        $body = "This is the form that was just submitted:
        Name:  $_POST[name]
        E-Mail: $_POST[email]
        Message: $_POST[message]";

        if( $_POST['
    email'] && !preg_match( "/[\r\n]/", $_POST['email']) ) {
          $headers = "From: $_POST[email]";
        } else {
          $headers = "From: $youremail";
        }

        
        mail($youremail, '
    Contact Form', $body, $headers );

    }

    ?>
    <!DOCTYPE HTML>
    <html>
    <head>

    <title>Thanks!</title>

    </head>
    <body>

    <h1>Thanks</h1>
    <p>We'
    ll get back to you as soon as possible.</p>

    </
    body>
    </
    html>
    This is the initial form

    PHP Code:
    <form action="submit.php" method="post" id="contact">
        <
    h3>Contact Form</h3>
        <
    fieldset>
            <
    label for="name">Name:</label><br>
            <
    input type="text" name="name" id="name"><br>
            <
    label for="email">E-Mail Address:</label><br>
            <
    input type="email" name="email" id="email"><br>
            <
    label class="antispam" for="url">Leave blank</label><br>
            <
    input type="url" name="url" id="url"><br>
            <
    label for="message">Message:</label><br>
            <
    textarea name="message" id="message" cols="30" rows="10"></textarea>
        </
    fieldset>
        <
    div class="submitsAndHiddens">
            <
    input type="submit" value="submit">
        <!-- .
    submitsAndHiddens --></div>
    </
    form><br/> 
    Last edited by quartzy; Aug 27th, 2017 at 11:22 AM.

  2. #2
    Regular Coder Synaptic's Avatar
    Join Date
    Apr 2015
    Location
    Las Vegas
    Posts
    241
    Thanks
    3
    Thanked 35 Times in 35 Posts
    Take a look at the Syntax highlighting, you never close the string assigned to $youremail

  3. #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    4,264
    Thanks
    3
    Thanked 554 Times in 539 Posts
    If you are seeing the php code in your browser, either -

    1) You have requested the form (which then requests the form processing code) directly in your browser, through the file system, not through a url on your localhost web server. A correct URL would look like http://localhost/your_form.php. A file system reference would look like file:///C:/Users/your_name/Desktop/your_from.php

    2) You don't have php installed or it is not working on your localhost web server.
    Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

  4. Users who have thanked CFMaBiSmAd for this post:

    quartzy (Aug 29th, 2017)

  5. #4
    Regular Coder
    Join Date
    May 2009
    Posts
    887
    Thanks
    137
    Thanked 24 Times in 24 Posts
    I guess I will have to upload it to my website under an obscure name. Thanks


 

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
  •