我在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 & 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文件中放入什么以将其与电子邮件一起发送?谢谢!!!
答案 0 :(得分:2)
在您的复选框name
中添加input
属性:
<input type="checkbox" id="hascurrent" name="hasCurrent" value="yes" />
然后在你PHP
中,只需将其作为其他变量阅读:
$hasCurrent = $_POST['hasCurrent'];
如果选中,则$hasCurrent
的值为yes
,否则为空。