php - 表单发送空白值

标签 php html css forms

<分区>

我正在使用 HTML、CSS 和 PHP 制作一个简单的表单。

目前,该表单向已识别的收件人发送一封电子邮件,但不包含来自该表单的任何信息,仅包含在 $formcontent 中识别的标题。

HTML

<form method ="post" action="index.php">      
    <input name="name" type="text" class="feedback-input" placeholder="Name" />   
    <input name="email" type="text" class="feedback-input" placeholder="Email" />
    <textarea name="message" class="feedback-input" placeholder="message"></textarea>
    <input id="submit" name="submit" type="submit" value="SUBMIT"/>
</form>

CSS

form { max-width:455px; margin-right:45px; margin-top:10px; float: right; display: inline; }

.feedback-input {
  color:white;
  font-family: Helvetica, Arial, sans-serif;
  font-weight:500;
  font-size: 18px;
  border-radius: 5px;
  line-height: 22px;
  background-color: transparent;
  border:2px solid #CC6666;
  transition: all 0.3s;
  padding: 13px;
  margin-bottom: 15px;
  width:100%;
  box-sizing: border-box;
  outline:0;
}

.feedback-input:focus { border:2px solid #CC4949; }

textarea {
  height: 60px;
  line-height: 60%;
  resize:vertical;
}

[type="submit"] {
  font-family: 'Montserrat', Arial, Helvetica, sans-serif;
  width: 100%;
  background:#CC6666;
  border-radius:5px;
  border:0;
  cursor:pointer;
  color:white;
  font-size:24px;
  padding-top:10px;
  padding-bottom:10px;
  transition: all 0.3s;
  margin-top:-4px;
  font-weight:700;
}
[type="submit"]:hover { background:#CC4949; }

PHP

<?php
$name = $_post['name'];
$email = $_post['email'];
$message = $_post['message'];
$formcontent = "From: $name \n Message: $message";
$recipient = 'info@beardmore.cc';
$subject = 'Beardmore.cc contact form';
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";?>

最佳答案

作为Albzi注意到in their comment ,在 PHP 中,这种情况很重要,您需要编辑代码以使用 $_POST 而不是 $_post:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent = "From: $name \n Message: $message";
$recipient = 'info@beardmore.cc';
$subject = 'Beardmore.cc contact form';
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";?>

您还应该清理您的变量,在这种状态下您的代码未受到恶意用户的保护。此外,检查它们是否设置为 isset功能。

关于php - 表单发送空白值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33152827/

上一篇:html - 使用 bootstrap 在行内将 2 张图片彼此居中

下一篇:javascript - html anchor 标记穿过屏幕

相关文章:

php - 如何在 jquery 中编写 PHP 代码以从 mysql 数据库检索值?

php - 同步 PHP 和 MySQL 时区

php - mysql 查询时间太长

html - 如何将此侧边栏应用到所有使用 CSS 的页面?

php - 为什么 Php Media Gallery 不工作?

php - 在数据库中存储 PHP session 数据的最佳实践是什么?

javascript - 如何从 HTML-PhP 的表中的查询列表中运行特定查询

php - 带有固定 header 的可滚动 echo 数据库表

html - 三个内联 div 高度响应在 Firefox 上不起作用

html - 为什么 IE8 会忽略背景色?