我对PHP表单有疑问。如何通过电子邮件通过php发送文本和多个复选框?这是代码:
<form role="form" action="signup.php"
method="post" id="myform">
<div class="row opcje">
<div class="col-md-4">
<label class="checkbox">
<input name="checkbox" type="checkbox" checked="true" value="WOMEN">WOMEN</label>
</div>
<div class="col-md-4">
<label class="checkbox">
<input name="checkbox" type="checkbox" value="MEN" checked="true">MEN</label>
</div>
<div class="col-md-4">
<label class="checkbox">
<input name="checkbox" type="checkbox" value="KIDS" checked="true">KIDS</label>
</div>
</div>
<div class="form-group">
<input class="form-control" id="name" placeholder="NAME" type="text" name="name">
</div>
<div class="form-group">
<input class="form-control" id="email" placeholder="E-MAIL" type="email"
name="email">
</div>
<button type="submit" class="btn btn-lg btn-primary">SIGN UP</button>
</form>
和PHP:
<?php
$adresdo = "info@takelake.com";
$temat = "Newsletter signup";
$zawartosc = "Imie: ".$_POST['name']."\n"
."Email: ".$_POST['email']."\n";
if(!$_POST['name'] || !$_POST['email']){
header("Location: error.html");
exit;
}
$email = $_POST['email'];
if(mail($adresdo, $temat, $zawartosc, 'From: Subskrybent <'.$email.'>')){
header("Location: ok.html");
}
?>
如何在表单中添加复选框? 感谢
答案 0 :(得分:2)
HTML
<form role="form" action="signup.php"
method="post" id="myform">
<div class="row opcje">
<div class="col-md-4">
<label class="checkbox">
<input name="checkbox[]" type="checkbox" checked="true" value="WOMEN">WOMEN</label>
</div>
<div class="col-md-4">
<label class="checkbox">
<input name="checkbox[]" type="checkbox" value="MEN" checked="true">MEN</label>
</div>
<div class="col-md-4">
<label class="checkbox">
<input name="checkbox[]" type="checkbox" value="KIDS" checked="true">KIDS</label>
</div>
</div>
<div class="form-group">
<input class="form-control" id="name" placeholder="NAME" type="text" name="name">
</div>
<div class="form-group">
<input class="form-control" id="email" placeholder="E-MAIL" type="email"
name="email">
</div>
<button type="submit" class="btn btn-lg btn-primary">SIGN UP</button>
</form>
PHP
<?php
$adresdo = "info@takelake.com";
$temat = "Newsletter signup";
$zawartosc = "Imie: ".$_POST['name']."\n"
."Email: ".$_POST['email']."\n"
."Selected".implode($_POST['checkbox'],",");
if(!$_POST['name'] || !$_POST['email']){
header("Location: error.html");
exit;
}
$email = $_POST['email'];
if(mail($adresdo, $temat, $zawartosc, 'From: Subskrybent <'.$email.'>'))
{
header("Location: ok.html");
}
?>