0

我的 PHP 文件在网站的根文件夹中不起作用。如果它在另一个文件夹中,称为whatever,它可以工作。但它在根文件夹中不起作用。这是一张空白的白页。

这是一个简单的联系表格 (contact.html),其中contact.php包含处理表格的文件。我总是将它们放在同一个文件夹中。它不会在根目录下工作。

Contact.php 文件:

    <?php
    $subject = $_POST['sub'];
    $name = $_POST['name'];
    $from = $_POST['email'];
    $message = $_POST['msg'];
    $to = "stackoverflow@gmail.com";
    $send_email = mail($to,$subject,$message);
     if($send_email){
     echo "Your message is successfully sent!!!";
    }
    else{
     echo "Error in sending contact email!!!";
    }
    ?>

按要求添加了contact.html:

    <html>
    <body>
    <table>
    <form name="contact_form" method="post" action="contact.php">
    <tr>
    <td><b>PHP Contact Form</b></td>
    </tr>
    <tr>
    <td>Subject</td>
    <td><input name="sub" id="sub" type="text" size="75"></td>
    </tr>
    <tr>
    <td>Name:</td>
    <td><input name="name" id="name" type="text"></td>
    </tr>
    <tr>
    <td>Email</td>
    <td><input name="email" id="email" type="text"></td>
    </tr>
    <tr>
    <td>Message</td>
    <td><textarea name="msg" cols="60" rows="5" id="msg"></textarea></td>
    </tr>
    <tr>
    <td><input type="submit" name="Submit" value="Submit">
    </tr>
    </form>
    </table>
    </body>
    </html>

.htaccess 文件

    # Use PHP5 Single php.ini as default
    AddHandler application/x-httpd-php5s .php

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    # Adaptive-Images ------------------------------------------------------------------        -----------------

    # Add any directories you wish to omit from the Adaptive-Images process on a new         line, as follows:
    # RewriteCond %{REQUEST_URI} !some-directory
    # RewriteCond %{REQUEST_URI} !another-directory

    RewriteCond %{REQUEST_URI} !assets

    # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
    # to adaptive-images.php so we can select appropriately sized versions

    RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php

    # END Adaptive-Images -------------------------------------------------------------------------------
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
           RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule . /index.php [L]
            </IfModule>

            # END WordPress
4

2 回答 2

0

我有同样的问题,只有当我将contact.php移到另一个文件夹而不是root时才解决,例如:contact/contact.php并重新制作链接再见

于 2014-01-27T20:28:08.920 回答
0

action如果 formn.try 提供完整的 URL 以访问文件,您可能会犯错误。

1.Make一个页面名称联系人并进行如下操作:

   <form name="contact_form" method="post" action="/contact">

它会通过抓取它的 slug 将您重定向到联系页面。

或者

2.您可以设置一个bloginfo URL:

   <form name="contact_form" method="post" action="<?php bloginfo('template_url')?>/contact.php">

注意:不要忘记初始化global $wpdb;global $post;

于 2013-06-20T11:07:05.790 回答