配置我的PHP
嘿,我正试图找出我的表格的问题,以及我的挂断在代码中的位置。有人有什么建议吗配置我的PHP,php,forms,twitter-bootstrap,Php,Forms,Twitter Bootstrap,嘿,我正试图找出我的表格的问题,以及我的挂断在代码中的位置。有人有什么建议吗 <form method="post" action="tourney.php"> <div class="row"> <div class="col-sm-4"> <input class="form-control" type="text" placeho
<form method="post" action="tourney.php">
<div class="row">
<div class="col-sm-4">
<input class="form-control" type="text" placeholder="Name" name="tname">
</div>
<div class="col-sm-4">
<input class="form-control" type="text" placeholder="Email" name="temail">
</div>
<div class="col-sm-4">
<input class="form-control" type="text" placeholder="School or Club" name="tclub">
</div>
<br>
<br>
<div class="col-sm-4">
<input class="form-control" type="text" placeholder="Address" name="taddress">
</div>
<div class="col-sm-3">
<input class="form-control" type="text" placeholder="City" name="tcity">
</div>
<div class="col-sm-2">
<input class="form-control" type="text" placeholder="State" name="tstate">
</div>
<div class="col-sm-2">
<input class="form-control" type="text" placeholder="Zip" name="tstate">
</div>
</div>
<br>
<div class="row">
<div class="col-sm-12">
<textarea placeholder="Type your message here..." class="form-control" rows="5"></textarea>
</div>
</div>
<br>
<div class="row">
<div class="col-sm-6">
<select name="type" class="form-control">
<OPTION VALUE="None Selected" SELECTED>Please select one</OPTION>
<OPTION VALUE="Middle School">Middle School Tournamanet</OPTION>
<OPTION VALUE="Elementary">Elementary Tournament</OPTION>
</select>
</div>
<div class="col-sm-6 pull-right">
<input class="btn btn-danger" type="submit" value="Register">
</div>
</div>
</form>
请选择一个
中学旅游网
初级锦标赛
以及发送电子邮件的PHP:
<?php
if(isset($_POST['submit'])){
$from = "minguswrestling.com";
$to = "puremeld@gmail.com";
$name = $_POST['tname'];
$email = $_POST['temail'];
$school = $_POST['tclub'];
$address = $_POST['taddress'];
$city = $_POST['tcity'];
$state = $_POST['tstate'];
$zip = $_POST['tzip'];
$type = $_POST['type'];
$message = $_POST['tmessage'];
$subject = "Tourney Signup!";
$body = "From: $from \n Name: $name \n Email: $email \n School: $school\n Address: $address\n City: $city State: $state Zip: $zip\n Event: $type\n Message: $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
'<h2>Thank You!</h2>';
header("Location: index.html");
} else {
echo '<p>Oops! An error occurred. Try sending your message again. </p>';
}
}
}
?>
任何帮助都将不胜感激。我正在使用bootstrap进行构建,谢谢 以下内容:
'<h2>Thank You!</h2>';
header("Location: index.html");
“谢谢!”;
标题(“位置:index.html”);
如果错误,则不能在标题之前输出任何内容。删除:
'<h2>Thank You!</h2>';
“谢谢!”;
您的代码有一些问题
首先,正如我在评论中提到的;以下条件语句中的所有内容都不会激发:
if(isset($_POST['submit'])){...}
因为没有名为“submit”的表单元素,所以作为提交按钮和错误报告将向您抛出一个未定义索引提交通知…
因此,您需要将其修改为:
<input name="submit" class="btn btn-danger" type="submit" value="Register">
需要修改并添加name=“tmessage”
,因为$message=$\u POST['tmessage']代码>最有可能用于消息:
<textarea name="tmessage" placeholder="Type your message here..." class="form-control" rows="5"></textarea>
如果要使用标题,请记住不要使用“echo”。首先要在标题之前输出。如果(isset($\u POST['submit']){…}
谁没有错误检查\显示,那么这将永远不会发生?是你的问题是什么?试图从我的表格中收集信息并通过电子邮件发送。只是不是最好的。我在自学,所以我得到了讽刺,但有时你必须问谢谢你,我的人。我很感激你的知识滴。@dustincorsel不客气,Dustin。我希望这能让你成功。我确实做了一些编辑,所以您可能需要重新加载我的答案。如果它确实解决了问题,您可以将其标记为已解决。你没有义务这么做,但它会告诉每个人找到了解决方案。欢迎来到Stack,干杯。@Dustincorsel将一个问题标记为已解决,然后访问,然后对给出的答案执行相同的操作。它确实有效,但我更好地了解了正在发生的事情。
<textarea name="tmessage" placeholder="Type your message here..." class="form-control" rows="5"></textarea>
<input class="form-control" type="text" placeholder="Zip" name="tstate">
<input class="form-control" type="text" placeholder="Zip" name="tzip">
if (mail ($to, $subject, $body, $from)) {
'<h2>Thank You!</h2>';
header("Location: index.html");
}
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
<?php
if(isset($_POST['submit'])){
$from = "minguswrestling.com";
$to = "puremeld@gmail.com";
$name = $_POST['tname'];
$email = $_POST['temail'];
$school = $_POST['tclub'];
$address = $_POST['taddress'];
$city = $_POST['tcity'];
$state = $_POST['tstate'];
$zip = $_POST['tzip'];
$type = $_POST['type'];
$message = $_POST['tmessage'];
$subject = "Tourney Signup!";
$body = "From: $from \n Name: $name \n Email: $email \n School: $school\n Address: $address\n City: $city State: $state Zip: $zip\n Event: $type\n Message: $message";
if (mail ($to, $subject, $body, $from)) {
echo '<h2>Thank You!</h2>'; // either use echo
// header("Location: index.html"); // or header, not both. Comment one or the other out.
} else {
echo '<p>Oops! An error occurred. Try sending your message again. </p>';
}
}
else { echo "Submit is not set."; }
?>
header("Location: index.html");
exit;