#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    60
    Rep Power
    2

    Unhappy Can anyone figure out what's wrong with this form?


    Hi.
    I'm learning how to send e-mail off the user input from a form.

    And I was trying to make this script work on a server but the script isn't showing anything after I hit the "Send Message" button of the form.

    This script will eventually complemented by another script so that the user inputs will be sent to specified e-mail address in e-mail format.

    The script that I put below is one I'm talking about and was supposed to show user inputs before sending e-mail. It was supposed to be like a confirmation thing for user inputs so that you can actually see, before sending actual e-mail, what's going to be sent right below the "Send Message" button on the same page.

    Can anyone figure out what would is wrong with this script, please???!

    PHP Code:

    <?php
    include('./includes/title.inc.php');
    $errors = array();
    $missing = array();
    // check if the form has been submitted
    if (isset($_POST['send'])) {
      
    // email processing script
      
    $to 'david@example.com';
      
    $subject 'Feedback from Japan Journey';
      
    // list expected fields
      
    $expected = array('name''email''comments');
      
    // set required fields
      
    $required = array('name''comments''email');
      
    // create additional headers
      
    $headers "From: Japan Journey<feedback@example.com>\r\n";
      
    $headers .= 'Content-Type: text/plain; charset=utf-8';
      require(
    './includes/processmail.inc.php');
    }
    ?>
    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset=utf-8">
    <title>Japan Journey<?php echo "{$title}"?></title>
    <link href="styles/journey.css" rel="stylesheet" type="text/css" media="screen">
    </head>

    <body>
    <div id="header">
        <h1>Japan Journey</h1>
    </div>
    <div id="wrapper">
        <?php include('./includes/menu.inc.php'); ?>
        <div id="maincontent">
          <h2>Contact Us </h2>
            <?php if ($_POST && $suspect) { ?>
              <p class="warning">Sorry, your mail could not be sent. Please try later.</p>
            <?php } elseif ($missing || $errors) { ?>
               <p class="warning">Please fix the item(s) indicated.</p>
            <?php ?>
          <p>Ut enim ad minim veniam, quis nostrud exercitation consectetur adipisicing elit. Velit esse cillum dolore ullamco laboris nisi in reprehenderit in voluptate. Mollit anim id est laborum. Sunt in culpa duis aute irure dolor excepteur sint occaecat.</p>
            <form id="feedback" method="post" action="">
                <p>
                    <label for="name">Name:
                    <?php if ($missing && in_array('name'$missing)) { ?>
                      <span class="warning">Please enter your name</span>
                    <?php ?>
                    </label>
                    <input name="name" id="name" type="text" class="formbox"
                    <?php if ($missing || $errors) { 
                     echo 
    'value="' htmlentities($nameENT_COMPAT'UTF-8') . '"';
                    } 
    ?>>
                </p>
                <p>
                    <label for="email">Email:
                    <?php if ($missing && in_array('email'$missing)) { ?>
                      <span class="warning">Please enter your email address</span>
                    <?php } elseif (isset($errors['email'])) { ?>
                      <span class="warning">Invalid email address</span>
                    <?php ?>
                    </label>
                    <input name="email" id="email" type="text" class="formbox"
                    <?php if ($missing || $errors) { 
                     echo 
    'value="' htmlentities($emailENT_COMPAT'UTF-8') . '"';
                    } 
    ?>>
                </p>
                <p>
                    <label for="comments">Comments:
                    <?php if ($missing && in_array('comments'$missing)) { ?>
                      <span class="warning">Please enter your comments</span>
                    <?php ?>
                    </label>
                    <textarea name="comments" id="comments" cols="60" rows="8"><?php
                    
    if ($missing || $errors) {
                      echo 
    htmlentities($commentsENT_COMPAT'UTF-8');
                    } 
    ?></textarea>
                </p>
                <p>
                    <input name="send" id="send" type="submit" value="Send message">
                </p>
            </form>
            <pre>
            <?php if ($_POST && $mailSent) {
              echo 
    "Message body\n\n";
              echo 
    htmlentities($messageENT_COMPAT'UTF-8') . "\n";
              echo 
    "Headers\n\n";
              echo 
    htmlentities($headersENT_COMPAT'UTF-8');
            } 
    ?>
            </pre>
        </div>
        <?php include('./includes/footer.inc.php'); ?>
    </div>
    </body>
    </html>
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    8
    Rep Power
    0
    It looks like you're trying to rely on register globals being turned on. for example in this line :
    PHP Code:
    <?php if ($missing || $errors) {  
                     echo 
    'value="' htmlentities($emailENT_COMPAT'UTF-8') . '"'
                    } 
    ?>
    Where is $email defined?
    Make sure you have error_reporting set to -1 and display_errors turned on.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    2
    Right, well let's start with the basic things first. If your script is aborting and nothing is being outputted, that tells me the problem lies in:

    PHP Code:
    include('./includes/title.inc.php');
    $errors = array(); 
    $missing = array(); 
    // check if the form has been submitted 
    if (isset($_POST['send'])) { 
      
    // email processing script 
      
    $to 'david@example.com'
      
    $subject 'Feedback from Japan Journey'
      
    // list expected fields 
      
    $expected = array('name''email''comments'); 
      
    // set required fields 
      
    $required = array('name''comments''email'); 
      
    // create additional headers 
      
    $headers "From: Japan Journey<feedback@example.com>\r\n"
      
    $headers .= 'Content-Type: text/plain; charset=utf-8'
      require(
    './includes/processmail.inc.php'); 

    So what could cause the aborting? Well I suspect one thing:
    PHP Code:
    require('./includes/processmail.inc.php'); 
    The require statement will abort the whole script if it fails. Is it failing? Check (Turn on error reporting).

    To turn on error reporting:
    PHP Code:
     error_reporting( -);//at the top of the script 
    There could be more code in the included file (title.inc.php) and the required file (processmail.inc.php) that could be causing the aborting. But as you haven't posted the contents of any of those files, I can't help you with that.

    Also, I'm just curious to know; if you hate PHP, why are you using it?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    60
    Rep Power
    2

    Thanks


    Okay, I just put error_reporting( -1); right after the '<?php' and now I was just trying to how to turn on display_errors.

    But, to turn on display_errors on, I would have to go to php.ini file, right?

    I was trying to find out how to get to the php.ini file.
    And I came across this online article that says I have to create a file with "<?php phpinfo(); ?>" in it so that I can check out basic information of my php environment or whatever.

    So I did it and it turned out the php.ini file is located at "/opt/httpd/php.ini"

    And I have a question,,,

    WHAT IS "/opt/httpd/php.ini"??
    How can I get there in my directly???
    Is that even inside my public_html directly??????
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    60
    Rep Power
    2

    Thanks navnav


    Thanks for you suggestion but as I stated above, I got another problem over the course of finding out how to check errors.

    And this is exactly why I hate php. I say I hate php all the time.

    I like php when it works or does make sense to me.

    But the most of time, I can't figure out problems and I always turn to someone to teach me because instruction doesn't make sense to me, either..
    I hate the instruction always assume readers have enough knowledge to understand its explanation with a bunch of technical terms..

    So the reason why I hate php, or I say I hate php, is because I'm dumb.
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    2
    Originally Posted by Ihatephp
    Thanks for you suggestion but as I stated above, I got another problem over the course of finding out how to check errors.

    And this is exactly why I hate php. I say I hate php all the time.

    I like php when it works or does make sense to me.

    But the most of time, I can't figure out problems and I always turn to someone to teach me because instruction doesn't make sense to me, either..
    I hate the instruction always assume readers have enough knowledge to understand its explanation with a bunch of technical terms..

    So the reason why I hate php, or I say I hate php, is because I'm dumb.
    Fair enough.

    But if you have error_reporting(-1); at the top of your script, you should not have to turn it on in your php.ini. At least not for that script anyway. Also, this should already be turned on in your ini config. Have you turned it off in the past?

    You say you used phpinfo(); to get the location of your ini file. Well I have some good news, phpinfo(); also tells you if error_reporting is switched on or not. What is the value of error_reporting from phpinfo();? You can easily find it by running phpinfo(); again and scrolling down to "configuration".

    I have a big feeling you're wasting your time looking for the ini config file when error_reporting is already switched on.

    So what was preventing errors displaying in your script? I would suspect something in the included file(s). Did you download those included files or did you write them yourself? If you did download them, look for any one of these pieces of code and remove them (from the included file) as they could be preventing your script from displaying errors.

    PHP Code:
    error_reporting(0);
    error_reporting(E_ERROR E_WARNING E_PARSE);
    error_reporting(E_ERROR E_WARNING E_PARSE E_NOTICE); 
    If you can't find any of the above in your included files, then it most probably is your ini file (but check your phpinfo(); first!).

    WHAT IS "/opt/httpd/php.ini"??
    Strictly speaking, it's a path to your ini config file.

    How can I get there in my directly???
    This depends. If you're using shared host, I doubt you will be able to access your httpd directory. And if that's the case, I seriously doubt error_reporting has been turned off. However, if you're using your own server or a dedicated/virtual dedicated server, then you can easily get to this directory through FTP.

    Is that even inside my public_html directly??????
    No, it looks like it's above that.


    Okay, so as you've already ranted about before, the above will probably be a little too complicated for you.

    Here's an easy solution out of this (if the problem really does lie in your ini config):

    If you REALLY do have error_reporting turned off in your ini and you cannot access your ini for whatever reason, you will be pleased to know that you can overwrite any ini settings by placing another PHP ini config file in your site root.

    So, open Notepad and paste this into it:
    PHP Code:
    error_reporting E_ALL & ~E_NOTICE 
    Then save the file with the name php.ini. Make sure you save it in your site/app root. Then, any script you have under/in that root will also listen to that php.ini file.

    However, this will only work if your host allows it. Believe it or not, some silly hosts actually don't. If yours don't, I suggest moving to another host.
  12. #7
  13. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,301
    Rep Power
    7170
    You can turn on display errors using ini_set:
    PHP Code:
    ini_set('display_errors'1); 
    display_errors is off by default in production environments. Both error_reporting and display_errors need to be set in order for you to see error messages.

    However, note that neither error_reporting nor ini_set will work if the fatal error is due to a syntax error in the file containing them. This is why development systems should have error_reporting and display_errors set in the php.ini file instead of in the script.

    As mentioned, a shared host won't let you modify php.ini directly. However, they usually provide a method of setting php.ini values. Some provide this using a secondary php.ini file that you can modify; some provide it using .htaccess files; and some provide it via a custom control panel. If in doubt, you should contact your host for more details.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    60
    Rep Power
    2

    thanks


    Thank you very much.

    >>What is the value of error_reporting from phpinfo();?

    Okay, I checked the phpinfo() file and its error_reporting value is set to 2047..What is it?......

    And the display_errors's value is set to "off" on the phpinfo() file..

    I also looked for these codes in includes files.

    PHP Code:
     error_reporting(0);
    error_reporting(E_ERROR E_WARNING E_PARSE);
    error_reporting(E_ERROR E_WARNING E_PARSE E_NOTICE); 
    and I couldn't find any of them in the includes files.

    I also found out the included files aren't specified right.
    It turned out the URLs have "./includes" before the files but those files and the file we are talking about are in the same folder..

    This is the files I downloaded to learn php.. and I don't understand why this material is made this way..
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Oxford, United Kingdom
    Posts
    40
    Rep Power
    2
    Originally Posted by Ihatephp
    Thank you very much.

    >>What is the value of error_reporting from phpinfo();?

    Okay, I checked the phpinfo() file and its error_reporting value is set to 2047..What is it?......

    And the display_errors's value is set to "off" on the phpinfo() file..

    I also looked for these codes in includes files.

    PHP Code:
     error_reporting(0);
    error_reporting(E_ERROR E_WARNING E_PARSE);
    error_reporting(E_ERROR E_WARNING E_PARSE E_NOTICE); 
    and I couldn't find any of them in the includes files.

    I also found out the included files aren't specified right.
    It turned out the URLs have "./includes" before the files but those files and the file we are talking about are in the same folder..

    This is the files I downloaded to learn php.. and I don't understand why this material is made this way..
    And the display_errors's value is set to "off" on the phpinfo() file..
    There is your problem. Try to follow my instructions from my previous post to create a new lower level ini file but have this pasted in it (instead of what I said before):
    PHP Code:
    display_errors on 
    I think 2047 is E_ALL which reports all errors (except notices?), so error reporting is enabled (like I said it would be ).

    Also, you should note; when you create the ini to change your display_errors settings, only have it there during your development process. Once you've deployed (made live for everyone to use) your app/site, you should change the setting back to off. Showing errors to random people is not a good idea and could promote attacks.

    I also found out the included files aren't specified right.
    It turned out the URLs have "./includes" before the files but those files and the file we are talking about are in the same folder..
    So that's what was aborting your script. When you make the new ini file, I would suggest (deliberately) messing it up again (to cause a fatal error), so you can make sure it displays errors.

    This is the files I downloaded to learn php.. and I don't understand why this material is made this way..
    Using code from the net because you're too lazy to write it is one thing, but using it because you don't know how to write it is a complete different thing (in a bad way).

    Because you don't know how to write it, chances are, you wont have a clue of what half the code you take from the net does. What if it blows up your server? What if it sends 10 million spam messages to random email addresses (getting your IP blacklisted)? What if it opens up every file on your machine and sends all contents to a remote party? It's different if you already know how to do it, but you're just to lazy to do it, because you can just scan through the code you take from the net and make sure it does nothing dodgy. But when you don't know how to code, you can't do that. So taking code from the net is far from a good idea IMHO.

    My advice? Learn it. I know it can be frustrating at times, but that's programming in general. Once you get to know PHP, you'll love it.

IMN logo majestic logo threadwatch logo seochat tools logo