Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使表单工作_Php_Html_Forms - Fatal编程技术网

Php 如何使表单工作

Php 如何使表单工作,php,html,forms,Php,Html,Forms,我在一个PHP页面中创建了一个表单,如果它属于我的话,我想我已经做好了一切。但是当我把它上传到服务器时,它就不工作了。如何修复它 这是我的密码: <section class="body"> <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $from = 'From: TangledDemo'; $to = 'contact@tangledindesign

我在一个PHP页面中创建了一个表单,如果它属于我的话,我想我已经做好了一切。但是当我把它上传到服务器时,它就不工作了。如何修复它

这是我的密码:

<section class="body">
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: TangledDemo';
$to = 'contact@tangledindesign.com';
$subject = 'Hello';
$human = $_POST['human'];

$body = "From: $name\n E-Mail: $email\n Message:\n $message";

if ($_POST['submit'] && $human == '4') {
    if (mail ($to, $subject, $body, $from)) {
        echo '<p>Your message has been sent!</p>';
    } else {
        echo '<p>Something went wrong, go back and try again!</p>';
    }
} else if ($_POST['submit'] && $human != '4') {
    echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
<form method="post" action="new.php">

<label>Name</label>
<input name="name" placeholder="Type Here">

<label>Email</label>
<input name="email" type="email" placeholder="Type Here">

<label>Message</label>
<textarea name="message" placeholder="Type Here"></textarea>

<label>*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">

<input id="submit" name="submit" type="submit" value="Submit">

</form>
</section>

名称
电子邮件
消息
*什么是2+2?(反垃圾邮件)
所以我得到的错误是我的现场站点上的整行代码

Your message has been sent!</p>';
    } else {
        echo '<p>Something went wrong, go back and try again!</p>';
    }
} else if ($_POST['submit'] && $human != '4') {
    echo '<p>You answered the anti-spam question incorrectly!</p>';
}
?>
您的邮件已发送

",; }否则{ echo“出现问题,请返回并重试!

”; } }否则如果($_POST['submit']&&$human!='4'){ echo“您错误地回答了反垃圾邮件问题!

”; } ?>
您的web服务器似乎不支持PHP。PHP在web服务器(又名服务器端)上运行,而客户端(即web浏览器)只应获取有效的HTML

看起来您的Web服务器没有解释PHP。快速检查是在浏览器中查看源代码——如果您在那里看到PHP代码,那么Web服务器没有运行PHP


PHP没有被解释有很多可能的原因——PHP扩展没有被处理、PHP没有被安装、其他web服务器配置等等。

你的反垃圾邮件系统真的很有趣,注意机器人很聪明,可以做这种类型的计算。为什么不改为使用验证码。@user689图像验证码比文本问题好不了多少。尽管我同意算术问题很容易通过编程解析和回答。不过,还有更好的方法,比如测试常识或从句子中选择某些字母。在你上传之前,这些方法有效吗?(你测试过吗?)它提交了没有?你能解释一下什么部分不起作用以及你是如何调试它的吗?看起来它只是在提供文件,而没有运行服务器端代码(即PHP没有运行,只是直接发送到浏览器)。如果您在web浏览器中查看源代码,您看到PHP代码了吗?再次感谢ernie,我是新手,所以我不知道。这是一个学校项目,所以他们的服务器不支持php,我相信。