我已经设置了一个PHP邮件表单设置,只能正确输出表单中输入的一些变量。它发送$ name和$ email变量,但不发送$ message变量。
发送表单的php在这里:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST" ){
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$message = trim($_POST["message"]);
//sending email
require_once("siteIncludes/class.phpmailer.php");
$mail = new PHPMailer();
$email_body = "";
$email_body = $email_body . "Name: " . $name . $message . "<br />";
$email_body = $email_body . "Email: " . $email . "<br />";
$email_body = $email_body . "Message: " . $message;
$mail->SetFrom("$email,$name");
$address = "foo@bar.com";
$mail->AddAddress($address);
$mail->Subject = "Form Submission | ".$name;
$mail->MsgHTML($email_body);
if(!$mail->Send() ){
echo 'There was a problem sending the email: '.$mail->ErrorInfo;
exit();
}
header("Location: myContact.php?status=thanks");
exit();
};
?>
设置表单的HTML就在这里:
<div id="contactFormWrap" class="span6 offset3">
<form method="post" action="myContact.php" id="contactForm">
<div>
<label for="name">Please leave your name</label>
<input type="text" name="name" id="name" value="" class="required" />
</div>
<div>
<label for="email">and your email</label>
<input type="text" name="email" id="email" value="" class="required email" />
</div>
<div>
<label for="subject">What is your message about?</label>
<input type="text" name="subject" id="subject" value="" class="required" />
</div> -->
<div>
<label for="message">and your message</label>
<textarea name="message" id="message" value="" rows="10" class="required"></textarea>
</div>
<div id="messageButtons">
<input type="submit" value="Submit" name="contactSubmit" id="contactSubmit" class="sendEmail btn" />
</div>
</form>
</div>
我希望这是足够的信息。有谁知道为什么$ message变量没有输出到提交的电子邮件?
感谢
答案 0 :(得分:6)
我认为这是你的问题:
value=""
<textarea>
代码does not have a value
attribute,但是不同的浏览器有不同的处理无效代码的方式,因此您使用的任何浏览器都必须使用此无效属性中的值而不是您在实际文本框。
只是做:
<textarea name="message" id="message" rows="10" class="required"></textarea>