【问题标题】:PHP file sends my form with everything but the "textarea"PHP文件发送我的表单,除了“textarea”之外的所有内容
【发布时间】:2014-06-25 06:44:39
【问题描述】:

我的网站上有一个表格,可以发送到我的电子邮件。效果很好,只是它拒绝使用作为文本区域的字段“描述”。我尝试过各种各样的事情。我是一名前端开发人员,所以我对 PHP 了解不多...

<div class="form">
                    <FORM METHOD="POST" ACTION="projectplanner.php">
                        <div class="form-spacing">
                        <INPUT TYPE="text" NAME="name" SIZE="30" placeholder="First & Last name" id="form-font">
                        </div>
                        </br>
                        <div class="form-spacing">
                        <INPUT TYPE="text" NAME="email" SIZE="30" placeholder="Email Address"  id="form-font">
                        </br>
                        </div>
                        <div class="form-spacing">
                        <INPUT TYPE="text" NAME="TimeZone" SIZE="30" placeholder="Time Zone"  id="form-font">
                        </div>
                        </br>
                        <div class="form-spacing">
                         <INPUT TYPE="text" NAME="Location" SIZE="30" placeholder="Location"  id="form-font">
                         </div>
                        <br>
                        <div class="form-spacing">
                        <textarea rows="10" cols="90" NAME="description"  placeholder="Briefly describe what you are looking for."  id="form-font"></textarea>
                        </div>
                        <br>
                        <div class="form-spacing">

                         <INPUT TYPE="text" NAME="Budget" SIZE="30" placeholder="Enter your budget for the website"  id="form-font">
                        </div>
                        </br>
                        <a href="sent.html">


                        <div class="form-submit">

                        <INPUT TYPE="submit" >
                        </div>
                        </a>
                    </FORM>
                    </div>

对于我的 PHP 代码..

<?php
/* Set e-mail recipient */
$myemail = "REMOVED FOR PRIVACY";

/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$subject = check_input($_POST['Budget'], "Enter a budget");
$email = check_input($_POST['email']);
$comment = check_input($_POST['description']);

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "

Name: $name
E-mail: $email
Budget: $subject

Message:
$description

";

/* Send the message using mail() function */
mail($myemail, $subject, $message);

/* Redirect visitor to the thank you page */
header('Location: thankyou.html');
exit();

/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);    
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}

function show_error($myError)
{
?>
<html>
<body>

<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>

</body>
</html>
<?php
exit();
}
?>

【问题讨论】:

  • 使用 chrome 开发工具或 firebug 检查实际发送的内容

标签: php html forms web


【解决方案1】:

您将描述存储在名为$comment 的变量中。然后尝试稍后将其引用为$description。我相信你正在寻找的是这样的:

Message:
$comment

【讨论】:

  • 有时多一双眼睛会有所帮助:)
猜你喜欢
  • 1970-01-01
  • 2012-08-01
  • 1970-01-01
  • 2013-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-28
  • 2018-09-17
相关资源
最近更新 更多