我的PHP文件无法在网站的根文件夹中使用。如果它在另一个文件夹中,称为无论什么,它就可以了。但它不能在根文件夹中工作。这是一个空白的白页。
这是一个简单的联系表单(contact.html),其中包含contact.php
文件来处理表单。我总是将它们放在同一个文件夹中。它不能在root中运行。
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
答案 0 :(得分:0)
如果formn.try提供完整的URL来访问该文件,您可能在action
处犯了错误。
1.建立页面名称联系并执行以下操作:
<form name="contact_form" method="post" action="/contact">
它会通过抓住它的slug将你重定向到联系页面。
OR
2.您可以设置bloginfo网址:
<form name="contact_form" method="post" action="<?php bloginfo('template_url')?>/contact.php">
注意:不要忘记初始化 global $wpdb;
和global $post;
答案 1 :(得分:0)
我有同样的问题,只有当我将contact.php移动到另一个文件夹而不是root,ex:contact / contact.php并重新设置链接时解决了 再见