Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9
  1. #1
    Member celticshinobi's Avatar
    Join Date
    Nov 2012
    Location
    TN, USA
    Posts
    36
    Member #
    33858
    Liked
    1 times
    Hey everyone - I apologize if this has been posted thousands of times - I've been working on some code for so long today, it's all running together - I've done so many searches, I cant remember where I've been and where I havent been...

    That being said, I'm having an issue with my contact form code - I've coded up a contact form; my html and css is all done - and I'm stumbling through some php now - as I understand it, I'll need some php to make the form work...

    Now when I use my form, instead of sending an email, it just pulls up my php file in my browser - would anyone be able to take a peek at my code and see where I've gone wrong?

    Thanks!
    Tom

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    The PHP files needs to be .php not .html ... or if it is .php and you can see
    the scripting, that means your webhost does not support PHP. Who is hosting
    your site?

    You didn't show us any code ... that makes it pretty hard to see.

    Show us the actual HTML form that the person fills out and submits.
    Show us the PHP script that is supposed to send the email.


  4. #3
    Member celticshinobi's Avatar
    Join Date
    Nov 2012
    Location
    TN, USA
    Posts
    36
    Member #
    33858
    Liked
    1 times
    Hey, I just wanted to check before I posted my code.

    That being said, I'll post it below - though when I ran the page this time, instead of showing the php file, it showed an error 405.0 - method not allowed page. I'm using IIS7 if that says anything..

    Here's the HTML code.

    <form action="mail.php" method="post"> <fieldset> <label for="name">Name:</label> <input type="text" id="name" placeholder="Enter your full name" /> <label for="email">Email:</label> <input type="email" id="email" placeholder="Enter your email address" /> <label for="message">Message:</label> <textarea id="message" placeholder="What's on your mind?"></textarea> <input type="submit" value="Send message" /> </fieldset> </form>




    And here's the PHP code


    <?php /* email address*/ $myemail = "keltichiro@fullsail.edu"; /* Check all form inputs using check_input function */ $name = check_input($_POST['name'], "Enter your name"); $subject = check_input($_POST['subject'], "Enter a subject"); $email = check_input($_POST['email']); $message = check_input($_POST['message'], "Write your message"); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } /* Let's prepare the message for the e-mail */ $message = " Name: $name E-mail: $email Subject: $subject Message: $message "; /* Send the message using mail() function */ mail($myemail, $subject, $message); /* Redirect visitor to the thank you page */ header('Location: thanks.html'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?> <html> <body> <p>Please correct the following error:</p> <strong><?php echo $myError; ?></strong> <p>Hit the back button and try again</p> </body> </html> <?php exit(); } ?>

  5. #4
    Member celticshinobi's Avatar
    Join Date
    Nov 2012
    Location
    TN, USA
    Posts
    36
    Member #
    33858
    Liked
    1 times
    oooh, I dont like how that formatted my code... if that's unreadable, let me know, I'll post it another way

  6. #5
    Member celticshinobi's Avatar
    Join Date
    Nov 2012
    Location
    TN, USA
    Posts
    36
    Member #
    33858
    Liked
    1 times
    actually scratch all of that...I believe it's working; I uploaded it to my web host that I know supports PHP - and it seems to work, although - now I get an error that says.. "please correct the following error - enter your name", even though I've tried entering just my first name, and first and last name

  7. #6
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    Try to repost the script in a read-able manner.

    I use notepad+ for all of my script editing.
    It numbers the lines for reference, color codes them, etc.
    http://notepad-plus-plus.org/

    And you're attending "Full Sail"? Very curious how that is going.
    We've had discussions here about some scripting courses they
    have taught that were a bit out-dated. Hopefully that has changed.


  8. #7
    Member celticshinobi's Avatar
    Join Date
    Nov 2012
    Location
    TN, USA
    Posts
    36
    Member #
    33858
    Liked
    1 times
    (edit - found an insert code button, that I shouldve seen before, so this should help)

    I'll give notepad+ a whirl - I'll post the code below from it and see how it formats... /cross fingers

    Full Sail is going well - I've been there for awhile now, the coding classes I've had have been up to date - the teachers have been adamant about writing current code (HTML5 and CSS3) and I've thoroughly enjoyed it. My previous college experience prior to Full Sail though, was a little different - I was being taught to design with tables, if that says anything.

    At any rate, here we go..code below...

    HTML Code:
        <form action="mail.php" method="post">
            <fieldset>
    
                <label for="name">Name:</label>
                <input type="text" id="name" placeholder="Enter your full name" />
    
                <label for="email">Email:</label>
                <input type="email" id="email" placeholder="Enter your email address" />
    
                <label for="message">Message:</label>
                <textarea id="message" placeholder="What's on your mind?"></textarea>
    
                <input type="submit" value="Send message" /><
    
            </fieldset>
        </form>
    PHP Code:
    <?php

    /* email address */
    $myemail "keltichiro@fullsail.edu";

    /* Check all form inputs using check_input function */
    $name check_input($_POST['name'], "Enter your name");
    $subject check_input($_POST['subject'], "Enter a subject");
    $email check_input($_POST['email']);
    $message check_input($_POST['message'], "Write your message");

    /* If e-mail is not valid show error message */
    if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/"$email))
    {
    show_error("E-mail address not valid");
    }
    /* Let's prepare the message for the e-mail */
    $message "

    Name: 
    $name
    E-mail: 
    $email
    Subject: 
    $subject

    Message:
    $message

    "
    ;

    /* Send the message using mail() function */
    mail($myemail$subject$message);

    /* Redirect visitor to the thank you page */
    header('Location: thanks.html');
    exit();

    /* Functions we used */
    function check_input($data$problem='')
    {
    $data trim($data);
    $data stripslashes($data);
    $data htmlspecialchars($data);
    if (
    $problem && strlen($data) == 0)
    {
    show_error($problem);
    }
    return 
    $data;
    }

    function 
    show_error($myError)
    {
    ?>
    <html>
    <body>

    <p>Please correct the following error:</p>
    <strong><?php echo $myError?></strong>
    <p>Hit the back button and try again</p>

    </body>
    </html>
    <?php
    exit();
    }
    ?>

  9. #8
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    In your form, for each form tag, add the property called 'name' ...

    <input type="text" id="name" name="name" placeholder="Enter your full name" />
    <input type="email" id="email" name="email" placeholder="Enter your email address" />
    <textarea id="message" name="message" placeholder="What's on your mind?"></textarea>

    You are using $_POST['subject'] in your script, but you are not using it in your HTML form.
    That's OK though ... you don't ever want anyone to be able to enter the actual email subject.
    If they can enter the subject, they can force emails to be filtered or use possible injections.

    Ask your instructor about sanitizing all input variables for not only email scripts, but all PHP scripts.

    So, replace this line:
    $subject = check_input($_POST['subject'], "Enter a subject");

    With this:
    $subject = "Message from contact form";
    (or some subject that you will recognize when viewing your email).

    Always handle email 'subject' yourself.
    If you need them to enter a subject, add it to the email message itself, not the email 'subject'.
    AlphaMare likes this.


  10. #9
    Member celticshinobi's Avatar
    Join Date
    Nov 2012
    Location
    TN, USA
    Posts
    36
    Member #
    33858
    Liked
    1 times
    it works like a charm, I really appreciate it!

    It's always a small detail I overlook when I have an issue like this, lol


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:39 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com