I need help with value sending to mail from form on html page, there is 3 file: test.html with form group checkbox, contact.php and contact.js
This is the contact.js:
$(function () {
$('#contact-form').validator();
$('#contact-form').on('submit', function (e) {
if (!e.isDefaultPrevented()) {
var url = "contact.php";
$.ajax({
type: "POST",
url: url,
data: $(this).serialize(),
success: function (data)
{
var messageAlert = 'alert-' + data.type;
var messageText = data.message;
var alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' + messageText + '</div>';
if (messageAlert && messageText) {
$('#contact-form').find('.messages').html(alertBox);
$('#contact-form')[0].reset();
}
}
});
return false;
}
})
});
and this is contact.php for processing form to mail
$fields = array('name' => 'Name', 'surname' => 'Surname', 'phone' => 'Phone', 'email' => 'Email', 'message' => 'Message' 'checkboxes' => 'Colors');
form group is:
<div class="form-group">
<div class="col-md-12">
<label>Colors:</label>
</div>
<div class="col-md-12">
<label class="checkbox-inline" for="form_checkboxes1">
<input type="checkbox" name="checkboxes[]" id="form_checkboxes1" value="Blue"> + Blue
</label>
<label class="checkbox-inline" for="form_checkboxes2">
<input type="checkbox" name="checkboxes[]" id="form_checkboxes2" value="Green"> + Green
</label>
<label class="checkbox-inline" for="form_checkboxes3">
<input type="checkbox" name="checkboxes[]" id="form_checkboxes3" value="Orange"> + Orange
</label>
</div>
the problem is when choose an option for Colors or choose every three colors after mail sent result is Colors: array
now, I trie to change line in contact.php adding
$checkboxes = implode(',',$_POST['checkboxes']);
but no succsess
rest of kod in contact.php is:
try{
$emailText = "text";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value
";}
}
mail($sendTo, $subject, $emailText, "From: " . $from);
$responseArray = array('type' => 'success', 'message' => $okMessage);
}