【发布时间】:2015-05-05 19:06:24
【问题描述】:
您好,我是 PHP 新手,我决定尝试为我正在创建的网站创建一个表单。除了发送复选框数据之外,我设法做到这一点以转到我的邮件地址 - 如果选中了多个复选框,则仅在已发布的电子邮件中显示最后一个选中的复选框。谁能让我知道我该怎么做? 这是 www.newsite0914.i4dsign.co.uk/contact.php 中的表单代码:
<form id="contact_form2" name="contact_formB" method="post" action="post.php">
.....
<table border="0" cellpadding="0" cellspacing="0" width="100%" id="nestedTable2">
<tr>
<td colspan="2">
Services interested in?
</td>
</tr>
<tr>
<td valign="top">
Website <input type="checkbox" name="service[]" value="web" />
</td>
<td align="right">
Logo <input type="checkbox" name="service[]" value="logo" style=" margin-right: 50px;" />
</td>
</tr>
<tr>
<td>
Stationery <input type="checkbox" name="service[]" value="stationery" />
</td>
<td valign="top" align="right" >
Advert <input type="checkbox" name="service[]" value="advert"style=" margin-right: 50px;" />
</td>
</tr>
<tr>
<td valign="top" colspan="2">
Other <input type="checkbox" name="service[]" value="other" /> <textarea cols="25" rows="1" name="other" value="other"style="margin-left: 10px;"></textarea>
</td>
</tr>
</table>
...
<tr>
<td colspan="2">
Security Task: 6 + 7 =
<input name="security" size="2" />
<input type="submit" value="Send your details" onClick="checkDetailsB()" style="margin-left: 20px;" />
<!--<input type="reset" value="Reset" />-->
</td>
</tr>
</table>
</form>
这里是 post php 脚本 (www.newsite0914.i4dsign.co.uk/post.php):
$to = "julian@i4dsign.co.uk";
$subject = "New Contact Form Submission";
$message = "....\n\nService: $service[$i]\n\n....";
if ($security=="13"){
mail($to,$subject,$message);
header("Location:contact.php?s=1");
}
else{
header("Location:contact.php?s=2");
}
提前谢谢你。我希望有人可以提供帮助。
【问题讨论】:
-
很难确定,因为您没有包含很多 PHP 代码。您在
$_POST['service']中传递了一系列服务,但看起来您只向$message添加了一个条目。你在哪里设置$i?