0

我在 html5 文档中使用了一个超级简单的表单。目前我不需要验证器或任何花哨的东西,但我无法找出如何将复选框的结果包含在电子邮件中。

html中的表单代码为:

<div id="subscribe_form">
<form action="mail.php" method="post" target="_blank">

 <input type="text" name="name" placeholder="Name" /><br>

<input type="email" name="email" placeholder="Email" /><br>

<textarea name="message" rows="6" cols="30" placeholder="Mailing Address" ></textarea><br />


<input type="checkbox" id="hascurrent" value="yes" />
<label for="hascurrent">I've already received the current issue of Critters &amp; Gods.</label>

<br>
<button type="submit" value="Send">Subscribe</button>

</form>

整个 mail.php 表单包括:

<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="Subscriber: $name Email: $email Address: $message Has current issue: $hascurrent";
$recipient = "subscriptions@crittersandgods.com";
$subject = "New Subscription";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "<div id='form_echo'> Thank you, $name, for subscribing to Critters & Gods. Your subscription is completely free and will not expire. If at any time you wish to unsubscribe from Critters & Gods, visit the about page for information. </div>";
?>

我是否在 html5 中正确格式化了复选框(它显示得很好,但我的编码是否正确?)以及我在 php 文件中放置了什么以使其与电子邮件一起发送?谢谢!!!

4

1 回答 1

2

name为您的复选框添加一个属性input

<input type="checkbox" id="hascurrent" name="hasCurrent" value="yes" />

然后在你身上PHP,把它当作其他变量来读:

$hasCurrent = $_POST['hasCurrent'];

如果选中,则值为 ,$hasCurrent否则为yes空白。

于 2013-09-16T08:02:59.300 回答