获取复选框的值

Get the values of checkbox

我有一个带有一些复选框选项的联系表:

html :

     <div class="col-xs-6 col-md-6 form-group checkboxEight">
                 <div class="checkbox c-checkbox"><label><input type="checkbox" value="Seo"  name="service[]"/><span class="fa fa-check"></span>seo</label>
                    </div>          
                <div class="checkbox c-checkbox "><label><input type="checkbox" value="ppc" name="service[]"/><span class="fa fa-check"></span>ppc</label>

                </div> 
                <div class="checkbox c-checkbox "><label><input type="checkbox" value="social" name="service[]"/><span class="fa fa-check"></span>social media</label>

                </div> 
                <div class="checkbox c-checkbox "><label><input type="checkbox" value="web" name="service[]"/><span class="fa fa-check"></span>web & interface</label></div> 
            </div>

php :

foreach($_POST['service'] as $selected)
{
//$service[] = $selected;
    $service[] = trim($_POST['value']);

}

和$body

$subject = '[Contact Form] From '.$name;
    $body = "Name: $name \n\n Email: $email \n\n Tel: $tel \n\n URL: $url  \n\n  service: $selected  \n\n Comments: $comments"; 
    $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;

    wp_mail($emailTo, $subject, $body, $headers);
    $emailSent = true;

对于我 select 我想通过电子邮件接收的每个复选框。但是现在发生的是只发送最后的选择而不是那些已经选择的人。

试试下面的代码:

foreach( $_POST['service'] as $selected ) {
    $checked_boxes .= $selected . ' ';
}

$body = "Name: $name \n\n Email: $email \n\n Tel: $tel \n\n URL: $url  \n\n  service: $checked_boxes  \n\n Comments: $comments";