PHP Post 变量有问题
Trouble with PHP Post Variable
很难解释,但我一直对 PHP 中的 Post 变量有一些疑问。问题是我一直在 Repl.it 制作一个虚拟网站来练习 PHP 因为我是一个完全的初学者,所以我一直在尝试联系表格。
这是 PHP 代码作为文件名 "contact-form-handler.php":
<?php
$name = $_Post["name"]; $visitor_email = $_Post["email"]; $message = $POST['message'];
$email_from = "19braja@rgshw.com";
$email_subject = "New Form Submission For BXRSTUDIOS";
$email_body = "User Name: $name.\n ".
"User Email: $visitor_email.\n".
"User Message $message.\n";
$to = "19braja@rgshw.com";
$headers = "From: $email_from \r\n";
$headers = "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: contact.html");
?>
这是 HTML 代码,文件名为 "contact.html":
<html>
<head>
<link href="contact.css" rel="stylesheet" type="text/css" />
<title>Contact Form</title>
</head>
<body>
<div class="contact-title">
<h1> Want To Contact Us?</h1>
<h2> We are always here to help</h2>
</div>
<div class="contact-form">
<form id ="contact=form" method="post" action="contact-form-handler.php">
<input name="name" type="text" class="form-control" placeholder="Your Name" required><br>
<input name="email" type="email" class="form-control" placeholder="Your Email" required><br>
<textarea name="message" type="text" class="form-control" placeholder="Message to BXRSTUDIOS" row="4" required></textarea><br>
<input type="submit" class="form-control submit" value="SUBMIT MESSAGE">
<p class="back">Not what you needed?<a href="index.php"> Go Back</a>
</p>
</form>
</div>
</body>
</html>
有谁知道为什么 Post 变量不起作用?这是控制台上的内容:
[Thu Apr 16 18:28:08 2020] PHP Notice: Undefined variable: _Post in /home/runner/BXRSTUDIOS1/contact-form-handler.php on line 3
[Thu Apr 16 18:28:08 2020] PHP Notice: Undefined variable: _Post in /home/runner/BXRSTUDIOS1/contact-form-handler.php on line 4
[Thu Apr 16 18:28:08 2020] PHP Notice: Undefined variable: POST in /home/runner/BXRSTUDIOS1/contact-form-handler.php on line 5
sh: 1: /usr/sbin/sendmail: not found
[Thu Apr 16 18:28:08 2020] 172.18.0.1:60886 [302]: /contact-form-handler.php
[Thu Apr 16 18:28:08 2020] 172.18.0.1:60892 [200]: /contact.html
[Thu Apr 16 18:28:08 2020] 172.18.0.1:60898 [200]: /contact.css
[Thu Apr 16 18:28:08 2020] 172.18.0.1:60906 [200]: /back.jpg
欢迎来到 Whosebug,
$_Post变量无效,$_POST是系统保留变量,必须全部大写
所以你的代码应该是:
$name = $_POST["name"]; $visitor_email = $_POST["email"]; $message = $_POST['message'];
很难解释,但我一直对 PHP 中的 Post 变量有一些疑问。问题是我一直在 Repl.it 制作一个虚拟网站来练习 PHP 因为我是一个完全的初学者,所以我一直在尝试联系表格。 这是 PHP 代码作为文件名 "contact-form-handler.php":
<?php
$name = $_Post["name"]; $visitor_email = $_Post["email"]; $message = $POST['message'];
$email_from = "19braja@rgshw.com";
$email_subject = "New Form Submission For BXRSTUDIOS";
$email_body = "User Name: $name.\n ".
"User Email: $visitor_email.\n".
"User Message $message.\n";
$to = "19braja@rgshw.com";
$headers = "From: $email_from \r\n";
$headers = "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
header("Location: contact.html");
?>
这是 HTML 代码,文件名为 "contact.html":
<html>
<head>
<link href="contact.css" rel="stylesheet" type="text/css" />
<title>Contact Form</title>
</head>
<body>
<div class="contact-title">
<h1> Want To Contact Us?</h1>
<h2> We are always here to help</h2>
</div>
<div class="contact-form">
<form id ="contact=form" method="post" action="contact-form-handler.php">
<input name="name" type="text" class="form-control" placeholder="Your Name" required><br>
<input name="email" type="email" class="form-control" placeholder="Your Email" required><br>
<textarea name="message" type="text" class="form-control" placeholder="Message to BXRSTUDIOS" row="4" required></textarea><br>
<input type="submit" class="form-control submit" value="SUBMIT MESSAGE">
<p class="back">Not what you needed?<a href="index.php"> Go Back</a>
</p>
</form>
</div>
</body>
</html>
有谁知道为什么 Post 变量不起作用?这是控制台上的内容:
[Thu Apr 16 18:28:08 2020] PHP Notice: Undefined variable: _Post in /home/runner/BXRSTUDIOS1/contact-form-handler.php on line 3
[Thu Apr 16 18:28:08 2020] PHP Notice: Undefined variable: _Post in /home/runner/BXRSTUDIOS1/contact-form-handler.php on line 4
[Thu Apr 16 18:28:08 2020] PHP Notice: Undefined variable: POST in /home/runner/BXRSTUDIOS1/contact-form-handler.php on line 5
sh: 1: /usr/sbin/sendmail: not found
[Thu Apr 16 18:28:08 2020] 172.18.0.1:60886 [302]: /contact-form-handler.php
[Thu Apr 16 18:28:08 2020] 172.18.0.1:60892 [200]: /contact.html
[Thu Apr 16 18:28:08 2020] 172.18.0.1:60898 [200]: /contact.css
[Thu Apr 16 18:28:08 2020] 172.18.0.1:60906 [200]: /back.jpg
欢迎来到 Whosebug,
$_Post变量无效,$_POST是系统保留变量,必须全部大写
所以你的代码应该是:
$name = $_POST["name"]; $visitor_email = $_POST["email"]; $message = $_POST['message'];