我的网站上有一个表单。当用户提交表单时,我会收到电子邮件回复,但没有返回表单数据。我所看到的只是
Company:
Name:
Email:
Phone:
表单html如下:
<form method="post" action="send_survey.php" class="survey" >
<header><a href="../index.html"><img src="../img/PTS_Survey_logo.jpg" alt="Patterson Tubular Services Logo"></a>
Customer Survey</header>
<fieldset>
<section>
<label class="input">
<i class="icon-append icon-group"></i>
<input type="company" id="company" required placeholder="Company name">
</label>
</section>
<section>
<label class="input">
<i class="icon-append icon-user"></i>
<input type="name" id="name" required placeholder="Your name" >
</label>
</section>
<section>
<label class="input">
<i class="icon-append icon-envelope-alt"></i>
<input type="email" id="email" required placeholder="Your e-mail">
</label>
</section>
<section>
<label class="input">
<i class="icon-append icon-phone"></i>
<input type="phone" id="phone" placeholder="Your phone number">
</label>
</section>
</fieldset>
<footer>
<input id="submit" name="submit" type="submit" value="submit" class="button">Submit the survey</button>
</footer>
</form>
php代码如下:
<?php
/*Subject and email variables */
$emailSubject = 'PTS Site Test';
$emailTo = 'testemail@testemail.com';
/* Gather form information */
$company = $_POST['company'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$body = <<<EOD
<br><hr><br>
Company: $company <br>
Name: $name <br>
Email: $email <br>
Phone: $phone <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail ($emailTo, $emailSubject, $body, $headers);
/* Results rendered */
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=http://www.cudd.com/PTS-2014/index.html">';
?>
提前谢谢。
答案 0 :(得分:6)
HTML表单输入在POST中由元素的name
属性设置,而不是其id。您应该将name
属性设置为与每个输入元素上的ID相同。
答案 1 :(得分:2)
您的任何输入都没有name
属性
变化:
<input type="company" id="company" required placeholder="Company name">
要:
<input type="company" name="company" id="company" required placeholder="Company name">