我想讓我的php表單顯示哪些收音機已被選中。換句話說,當有人通過我的網站通過電子郵件與我聯繫時,我希望它顯示他們打勾的電臺。我嘗試了一切,但無法讓它工作!PHP複選框電子郵件不起作用
HTML代碼迄今 -
<table width="308" border="0">
<label>
<input type="radio" name="servicetype[]" value="checkbox" id="Technical Support" />
Technical Support</label>
<label>
<input type="radio" name="servicetype[]" value="checkbox" id="Information Services" />
Information Services</label>
<tr>
<td align="left">
<input name="Submit" type="submit" id="Submit" class="contact-class2" value="Send"/>
</td>
</tr>
</table>
</form>
PHP到目前爲止
<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];
$mail_to = 'www.example.com';
$subject = 'hello';
$servicetype = join(", ", $_REQUEST["servicetype"]);
if (isset($_POST['servicetype'])) {
foreach ($_POST['servicetype'] as $key => $val) {
// do what you need
}
}
$body_message = ''.$field_message."\n"."\n";
$body_message .= 'From: '.$field_name;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers );
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
window.location = 'Contact form.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
window.location = 'Contact form.html';
</script>
<?php
}
?>
$ _ POST將得到您的單選按鈕的值屬性,而不是ID。另外,如果他們是單選按鈕,你需要發送一個數組嗎?因爲你只能挑選一個。 – andrewsi 2013-05-14 17:26:22
當我發送表單時,它只顯示字段名稱和標題等,但不顯示任何複選框。整個領域是完全空白的。我是PHP的超級新手,所以我絕望地需要幫助:( – user2382274 2013-05-14 17:57:04