gpt4 book ai didi

PHP 查询表格不起作用?

转载 作者:太空宇宙 更新时间:2023-11-04 02:48:07 24 4
gpt4 key购买 nike

我正在尝试创建一个网站,但我的 PHP 和 html 无法正常工作!!当我输入数据时,网站不会将信息发送到我的电子邮件,并且在输入表单中,显示的是我的验证而不是占位符!!!请帮助!!!!:-)

我的html如下:

<form class="form-horizontal" role="form" method="post" action="index.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="Preferred Name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="<?php echo htmlspecialchars($_POST['email']); ?>">
</div>
</div>
<div class="form-group">
<label for="number" class="col-sm-2 control-label">Contact Number</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="number" name="number" placeholder="0000000000">
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars($_POST['message']);?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo $result; ?>
</div>
</div>

我的PHP如下:

$Tel = Trim(stripslashes($_POST['Tel'])); 
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\`content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

最佳答案

您还没有关闭表单标签并且在联系中没有给出帖子粘贴此代码并检查的值,并且在使用 html5 验证时它将使用占位符设置验证错误消息,例如请输入 + 您的占位符

  <form class="form-horizontal" role="form" method="post" action="index.php">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" name="name" placeholder="Preferred Name" value="<?php echo @htmlspecialchars($_POST['name']); ?>">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="<?php echo @htmlspecialchars($_POST['email']); ?>">
</div>
</div>
<div class="form-group">
<label for="number" class="col-sm-2 control-label">Contact Number</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="number" name="number" placeholder="0000000000" value="<?php echo @$_POST['your_contact_filed_name'] ?>">
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<textarea class="form-control" rows="4" name="message"><?php echo htmlspecialchars(@$_POST['message']);?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<input id="submit" name="submit" type="submit" value="Send" class="btn btn-primary">
</div>
</div>
<div class="form-group">
<div class="col-sm-10 col-sm-offset-2">
<?php echo @$result; ?>
</div>
</div>
</form>

关于PHP 查询表格不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33499971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com