复选框 表单中的值来自空白 PHP


Checkbox Value in form coming over blank PHP

我正在尝试检查检查的值以通过电子邮件显示,但它们显示为空白。 我正在使用引导验证代码。

我也尝试使用这些中的每一个,但没有运气:

$accounting_services = !empty($_POST['accounting_services[]']) ? array() : $_POST['accounting_services[]']; 
$accounting_services = !empty($_POST['accounting_services[]']) ? implode(' | ', $_POST['accounting_services[]']) 
$accounting_services = nl2br(implode(',',$_POST['accounting_services[]'];

这是我的 HTML:

    <div class="form-group">
         <label><h4>WHAT ACCOUNTING SERVICES/FUNCTIONS ARE NEEDED?</h4>Mark as many as necessary)</label>
         <div class="checkbox">
            <label><input type="checkbox" name="accounting_services[]" value="Accounts Payable - Entering bills"/>Accounts Payable - Entering bills</label>
         </div>
         <div class="checkbox">
            <label><input type="checkbox" name="Accounting_Services[]" value="Accounts Payable – Paying Bills w/ Approval"/>Accounts Payable – Paying Bills w/ Approval</label>
         </div>
         <div class="checkbox">
            <label><input type="checkbox" name="Accounting_Services[]" value="Accounts Receivable – Invoicing clients"/>Accounts Receivable – Invoicing clients</label>
         </div>
         <div class="checkbox">
            <label><input type="checkbox" name="Accounting_Services[]" value="Accounts Receivable – Entering receive payments and deposits"/>Accounts Receivable – Entering receive payments and deposits</label>
         </div>
</div>

这是PHP代码:

<?php
// check if fields passed are empty
if(empty($_POST['name'])        ||
   empty($_POST['businessname']) ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
    echo "No arguments Provided!";
    return false;
   }
    if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['accounting_services'])){
foreach($_POST['accounting_services'] as $accountingselected){
echo $accountingselected."</br>";
}
}
}
$name = $_POST['name'];
$businessname = $_POST['businessname'];
$to = 'email@email.com'; 
$email_subject = "Contact form submitted by:  $name from $businessname";
$email_body = "You have received a new message. 'n'n".
                  " Here are the details:'n 'n ".
                  "Name: $name 'n ".
                  "Business Name: $businessname 'n ".
                  "Accounting Services: $accountingselected 'n".;
$headers = "From: $email_address'n";
$headers .= "Reply-To: $email_address"; 
mail($to,$email_subject,$email_body,$headers);
return true;            
?>

按如下方式更改代码。

$accounting_services = isset($_POST['accounting_services']) ?$_POST['accounting_services'] : "";