PHP表单不起作用 [英] PHP Form doesnt work
本文介绍了PHP表单不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经将php脚本包含到了index.php中:
<?php
$ name = $ _POST ['name'];
$ email = $ _POST ['email'];
$ message = $ _POST ['message'];
$ from ='From:Andrewch';
$ to ='adreasch@gmail.com';
$ subject ='Hello';
$ human = $ _POST ['human'];
$ body =From:$ name\\\
电子邮件:$ email \\\
消息:\ $ $ message;
if($ _POST ['submit']&& $ human =='4'){
if(mail($ to,$ subject,$ body,$ from) ){
echo'< p>您的讯息已发送!< / p>';
} else {
echo'< p>出错了,请返回并重试!< / p>';
} else if($ _POST ['submit']&& $ human!='4'){
echo'< p>您回答了反垃圾邮件问题!错误< / p为H.';
}?>
而且html看起来像这样
< form method =postaction =>
< label>名称< / label>
< input name =nameplaceholder =输入此处>
< label>电子邮件< / label>
< input name =emailtype =emailplaceholder =输入此处>
< label>讯息< / label>
< label> *什么是2 + 2?< / label>
< input name =humanplaceholder =Type Here>
< input id =submitname =submittype =submitvalue =>
它让我重定向到最重要的是,它甚至不写成功文本。
我做错了什么?
ps:Web托管服务让我使用PHP。
解决方案
在您的代码中没有错误只需在提交
时删除value =
替换< input id =submitname =submittype =submitvalue =>
到
< input id =submitname =submittype =submit>
So im trying to make my form work, but it doesn't seem to be possible.
i've included the php script into the index.php :
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: Andrewch';
$to = 'adreasch@gmail.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>';
}?>
And the html looks like this
<form method="post" action="" >
<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?</label>
<input name="human" placeholder="Type Here">
<input id="submit" name="submit" type="submit" value="">
It just keeps me redirecting to top, it is not even write the success text.
What am i doing wrong?
P.s: Web hoster let me use PHP.
解决方案
nothing wrong in your code just remove value="" in submit
replace <input id="submit" name="submit" type="submit" value="">
to
<input id="submit" name="submit" type="submit" >
这篇关于PHP表单不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文