Reputation: 1791
I have a question regarding PHP form. How can I send the text and multiple checkboxes through php via email? Here is the code:
<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>
and PHP:
<?php
$adresdo = "[email protected]";
$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");
}
?>
How can I include checkboxes in the form? Thanks
Upvotes: 1
Views: 85
Reputation: 812
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 = "[email protected]";
$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");
}
?>
Upvotes: 2