Q:

Value from checkbox send by mail - PHP form

I have this PHP code on my backend
if(!empty($_POST['model_list'])) {
            foreach($_POST['model_list'] as $model) {
            }
        } else {
            throw new Exception('Choose the model.');
        }

When I receive the request from my front-end, the $_POST['model_list'] variable doesn't seem to contain the value that was specified in the front-end.
Here's my HTML code:
<input type="checkbox" value="A" name="model_list[]"><span>A</span>

I have an error:

Notice: Undefined variable: model in /form.php on line 17

Line 17: 
$body = "Name: $name \n E-mail: $email \n Phone number: $tel \n Serial number: $number \n Model: $model \n Message: $message \n";

Full code: 
<?php
if (isset($_POST["submit"])) {
    $name       = (string) $_POST['name'];
    $email      = (string) $_POST['email'];
    $message    = (string) $_POST['message'];
    $number     = (string) $_POST['number'];
    $tel        = (string) $_POST['tel'];
    $from       = 'name@domain.tld';
    $to         = 'name@domain.tld';
    $subject    = 'Form';

    $body = "Name: $name \n E-mail: $email \n Phone number: $tel \n Serial number: $number \n Model: $model \n Message: $message \n";

    try {
        if (!$name) {
            throw new Exception('Write name.');
        }
        if (!$email || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
            throw new Exception('Write correct e-mail');
        }
        if (!$message) {
            throw new Exception('Write message');
        }
        if (mail ($to, $subject, $body, $from)) {
            $result = "<center><div style='color:white;font-size:15px;font-weight:700;'>Your message has been sent</div></center>";
        } else {
            throw new Exception("Your message has not been sent, try again");
        }
        if(!empty($_POST['model_list'])) {
            foreach($_POST['model_list'] as $model) {
            }
        } else {
            throw new Exception('Choose the model.');
        }
    } catch(Exception $e){
        $result = "<center><div style='color:white;font-size:25px;font-weight:700;'>" . $e->getMessage() . "</div></center>";
    }

    echo $result;
}
?>

Thanks in advance.

A:

To get all the models in the email, use implode:
if (!empty($_POST['model_list'])) {
    $model = implode(', ', $_POST['model_list']);
} else {
    $model = '';
}

