php联系表单不会只提取一个字段,但其余的都可以

时间:2014-08-14 13:00:33

标签: php forms contact

大家好我接触表格有问题,它提交的很好,除了它之外的一切都没有拿到我需要的一个字段。

<form method="post" action="contact.php" name="contactform" id="contactform">
<fieldset>
<legend>Thanks for letting us know</legend>
<label for="name" accesskey="U"><span class="required">*</span> Full Name</label>
<input name="name" type="text" id="name" size="30" value="" />
<label for="names" accesskey="E"> &nbsp;&nbsp;Guest Names</label>
<input name="names" type="text" id="names" size="30" value="" />
<label for="phone" accesskey="P"><span class="required">*</span> Total Attending</label>
<input name="phone" type="text" id="phone" size="5" value="" />
<label for="subject" accesskey="S"><span class="required">*</span> Attending?</label>
<select name="subject" id="subject">
<option value="Will Be Attending">Yes we would love to</option>
<option value="Sorry Won't Make It">Sorry we can't make it</option>
</select>
<label style="width:201px;" for="comments" accesskey="C"> Dietary Requirements</label>
<textarea name="comments" cols="40" rows="3" id="comments" style="width: 350px;"></textarea>
<p><span class="required">*</span> Verification Code</p>
<label for="verify" accesskey="V">&nbsp;&nbsp;&nbsp;1 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" /><br /><br />
<input type="submit" class="submit" id="submit" value="Submit" />
</fieldset>
</form>

给我带来麻烦的字段是第二个叫名字的字段,表单将提交,但该部分只是空白。这是我的php文件

<?php
if(!$_POST) exit;
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");

$name     = $_POST['name'];
$names = $_POST['names'];
$phone   = $_POST['phone'];
$subject  = $_POST['subject'];
$comments = $_POST['comments'];
$verify   = $_POST['verify'];

if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} if(trim($phone) == '') {
echo '<div class="error_message">Attention! Total Attending Missing.</div>';
exit();
}   else if(!is_numeric($phone)) {
echo '<div class="error_message">Total Attending can only contain digits.</div>';
exit();
}
if(trim($subject) == '') {
echo '<div class="error_message">Attention! Will you be attending?</div>';
exit();
} else if(!isset($verify) || trim($verify) == '') {
echo '<div class="error_message">Attention! Please enter the verification number.</div>';
exit();
} else if(trim($verify) != '2') {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.      </div>';
exit();
}

if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$address = "myemail@gmail.com";

$e_subject = 'You\'ve been contacted by ' . $name . '.';

$e_body = "You have been contacted by $name with regards to $subject, their dietary requirements   are as follows." . PHP_EOL . PHP_EOL;
$e_content = "\"$comments\"" . PHP_EOL . PHP_EOL;
$e_reply = "$name 's additional guests are $names and total attending is $phone";

$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );

$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;

if(mail($address, $e_subject, $msg, $headers)) {

echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";

} else {

echo 'ERROR!';

}

任何人都可以帮助我,也许你可以发现我做错了什么。感谢

0 个答案:

没有答案