title: Value from checkbox send by mail - PHP form
body: <p>I have this PHP code on my backend</p>
  
  <pre><code>if(!empty($_POST['model_list'])) {
              foreach($_POST['model_list'] as $model) {
              }
          } else {
              throw new Exception('Choose the model.');
          }
  </code></pre>
  
  <p>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.</p>
  
  <p>Here's my HTML code:</p>
  
  <pre><code>&lt;input type="checkbox" value="A" name="model_list[]"&gt;&lt;span&gt;A&lt;/span&gt;
  </code></pre>
  
  <p>I have an error:</p>
  
  <blockquote>
    <p><strong>Notice:</strong> Undefined variable: model in /form.php on line 17</p>
  </blockquote>
  
  <p>Line 17: </p>
  
  <pre><code>$body = "Name: $name \n E-mail: $email \n Phone number: $tel \n Serial number: $number \n Model: $model \n Message: $message \n";
  </code></pre>
  
  <p>Full code: </p>
  
  <pre><code>&lt;?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 = "&lt;center&gt;&lt;div style='color:white;font-size:15px;font-weight:700;'&gt;Your message has been sent&lt;/div&gt;&lt;/center&gt;";
          } 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 = "&lt;center&gt;&lt;div style='color:white;font-size:25px;font-weight:700;'&gt;" . $e-&gt;getMessage() . "&lt;/div&gt;&lt;/center&gt;";
      }
  
      echo $result;
  }
  ?&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>