【发布时间】:2014-06-18 20:09:17
【问题描述】:
我有一个文本区域的 PHP 发布问题。我已经搜索了这个站点,建议的补救措施包括提取 textarea 的 ID,并确保您使用的是 htmlspecialchars。我都在做,但我仍然无法弄清楚为什么它不会发布我的 textarea 的内容。
HTML
<form method="post" action="email.php" name="contactform" id="contactform" class="form form-stacked c-form">
<input name="name" type="text" id="name" placeholder="Name" />
<input name="email" type="text" id="email" placeholder="E-mail" />
<textarea name="theTextArea" placeholder="Message"></textarea>
<input type="submit" class="submit btn outline" id="submit" value="Send message" />
</form>
PHP
$realName = $name = $theMessage = $subject = $WHATmessage = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$realName = test_input($_POST["name"]);
$name = test_input($_POST["email"]);
$theMessage = test_input($_POST["theTextArea"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$subject = 'SUPERGROUP Inquiry - ' . $realName . ' - [' .date("F j, Y, g:i a").']';
$WHATmessage = $realName . ' is looking forward to hearing from us!'.PHP_EOL.'Their email is: '. $name .'!'.PHP_EOL.'They said: "'.$theMessage.'"';
mail('hello@sprgrp.com', $subject, $WHATmessage );
【问题讨论】:
-
什么是“test_input”?如果你在寻找价值,你就没有得到它。你得到了“test_input”的结果。
-
test_input 只是通过 htmlspecialchars 运行数据。
-
啊。所以“test_input”是一个返回清理后的字符串的函数。这就说得通了。那么,你从中得到什么?或者,你试过没有那个吗?
-
我试过没有它,但我仍然一无所获。 var_dump($theMessage) 只产生我在开头设置的空白字符串。
-
你试过用单引号而不是双引号吗? PHP 可能对此很有趣。