For example, there are checkboxes with several options in the form:
<form> <input type="checkbox" name="ch[]" id="ch-1" value="val-1"> <input type="checkbox" name="ch[]" id="ch-2" value="val-2"> <input type="checkbox" name="ch[]" id="ch-3" value="val-3"> </form> In js, the usual form processing (not the essence):
$.ajax({ url: 'contacts.php', type: 'post', data: str }).done(function(msg) { .... } And there are contacts.php :
<?php define("CONTACT_FORM", 'test@mail.ru'); $subject = 'Заявка'; $ch = stripslashes($_POST['ch']); $sel = stripslashes($_POST['sel']); if(!empty($_POST['ch'])) { foreach($_POST['ch'] as $check) { $ch += $check; } } $message = ' <html> <head> <title>Заявка</title> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> </head> <body> <p>Значения чекбоксов : '.$ch.'</p> <p>Значение селекта : '.$sel.'</p> </body> </html>'; $mail = mail(CONTACT_FORM, $subject, $message, "MIME-Version: 1.0\r\n" ."From: ".$name." <".CONTACT_FORM.">\r\n" ."Reply-To: ".$email."\r\n" ."Content-type: text/html; charset=UTF-8\r\n"); if($mail){ echo "OK"; } ?> Either only one checkbox value comes to the mail, or 0 .
Question: what am I doing wrong in the .php file. How can I fix that all the checkbox values come to the mail?

if(!empty($_POST['ch'])) { foreach($_POST['ch'] as $check) { echo $check; } }if(!empty($_POST['ch'])) { foreach($_POST['ch'] as $check) { echo $check; } }How then to insert all values into$messageproblem? - HamStername="ch"->name="ch[]"somehow seems so. - Visman