My web hosting company says there is something wrong with PHP code

前端 未结 4 1661
北海茫月
北海茫月 2021-01-29 07:46

This is the PHP it suppose to connect to a contact.html page and then a thank you page after afterwards.I just wanted a contact form. it wont recognize files as .php.I did save

相关标签:
4条回答
  • 2021-01-29 08:11

    PHP will not execute in .html file extensions without server configuration (for example, a directive in a .htaccess file if you're using Apache).

    Since you appear to have a managed web hosting account, you may not be able to set this yourself. If you would like it, I would suggest asking your hosting provider. If not, renaming the file to have a .php file extension should work.

    0 讨论(0)
  • 2021-01-29 08:16

    You wrote that it's a file named contact.html or you try to connect to contact.html - is this correct? You should rather use contact.php.

    0 讨论(0)
  • 2021-01-29 08:24

    Try to check out if php is working:

    <?php phpinfo(); ?>
    

    If you see no output, your php-code won't be parsed, maybe because your contact-site has an *.html ending, it seemingly needs a *.php file ending, to be parsed,

    if you want to use the extension '*.html', you have to add some lines to your webserver - configuration file,

    have a look at this: maybe a solution

    0 讨论(0)
  • 2021-01-29 08:31

    Assuming that you wish to run this from a form, you will need to set your HTML form tag as follows:

    <form action="contact.php" method="post">
    

    You should then rename contact.html to contact.php (any text editor should be able to do this easily).

    Finally, you're using PHP's header() function, which will cause errors if you have output to the browser before it is called. This includes using PHP's echo struct. Your contact.php file should look like this (and be in the same directory as your HTML file containing the form):

    <?php
        $name = $_POST['name'];
        $email = $_POST['email'];
        $number = $_POST['number'];
        $message = $_POST['message'];
        $from = 'From:you'; 
        $to = 'me@hotmail.com'; 
        $subject = 'Hello';
        $human = $_POST['human'];
    
        $body = "From: $name\n E-Mail: $email\n Number: $number\n Message:\n $message";
    
    
    if ($_POST['submit']) {
        if ($name != '' && $email != '') 
        {
            if ($human == '4') 
            {                 
                if (mail ($to, $subject, $body, $from)) 
                { 
                    header("Location: thanks.html");
                } 
                else 
                { 
                    echo '<p>Something went wrong, go back and try again!</p>'; 
                } 
            } 
            else
            {
                echo '<p>You answered the anti-spam question incorrectly!</p>';
            }
        } 
        else 
        {
            echo '<p>You need to fill in all required fields!!</p>';
        }
    }
    ?>
    

    Note: I fixed your layout a little and changed some of the conditions that you were using. The first elseif was actually redundant, and an else will suffice.

    0 讨论(0)
提交回复
热议问题