试图以php格式发送电子邮件复选框[重复]

This question already has an answer here:

I have several checkboxes in a form. And I'm trying to echo those values into an email. Here is the HTML:

<input id="checkbox1" type="checkbox" name="work-check[]"><label for="checkbox2">App Design</label>
                        <input id="checkbox2" type="checkbox" name="work-check[]"><label for="checkbox1">Design</label>
                        <input id="checkbox3" type="checkbox" name="work-check[]"><label for="checkbox2">Email Design</label>
                        <input id="checkbox4" type="checkbox" name="work-check[]"><label for="checkbox1">Layout Design</label>
                        <input id="checkbox5" type="checkbox" name="work-check[]"><label for="checkbox1">Poster Design</label>
                        <input id="checkbox6" type="checkbox" name="work-check[]"><label for="checkbox2">Web Design</label>

And here is the PHP:

    <?php

    if ($_POST["submit"]) {


        if(!filter_var($_POST[email], FILTER_VALIDATE_EMAIL)) {

            echo '<div data-alert class="alert-box warning">E-mail is not valid</div>';
            $error=true;
        }

        if($error==false) {

            $result='<div data-alert class="alert-box success">Form Submitted</div>';

            $headers = array("From: myemail@mail.com",
            "Reply-To: myemail@mail.com",
            "X-Mailer: PHP/" . PHP_VERSION
            );
            $headers = implode("
", $headers);

            // the message
            // the message
        $msg = "
        First Name: ".$_POST['first_name']." 

        Last Name: ".$_POST['last_name']."

        Email: ".$_POST['email']."

        Options: ".implode(",", $_POST['work-check']);


            // use wordwrap() if lines are longer than 70 characters
            $msg = wordwrap($msg,70);

            $to = "myemail@mail.com";

            $subject = "New Request";

            mail($to, $subject, $msg, $headers);
        }
    }

    echo $result;
?>

I think I have it set up that I should get an array back called work-check. I just don't know php well enough to know how to cycle through that array and set the values I get back. I found something like this which I think might be going in the right direction:

        // The array will only contain the checked value of forms
        foreach($golfer as $g) {
       // can use checkbox value here

}

I'm not sure where in the php code that should go.

</div>

Store it as a string

    //Store the array from the post as an array
    $arr = $_POST['work-check'];
    //implode the array into a string variable
    $options = implode( ",", $arr );

Or, keep it as an array and iterate over it doing what you want.

    $arr = $_POST['work-check'];
    foreach ($arr as &$value) {
        ...
    }

    unset($value); // break the reference with the last element

See the PHP manual for some more usage examples of foreach and implode.

Give the checkboxes a value This should give you an idea:

<?php

if ( isset( $_POST['submit'] ) ) {
  $work = implode( '<br>', $_POST['work'] );
}

?>

<!DOCTYPE html>
<html>
<body>

<?= $work ?>

<form method="post">
  <input type="checkbox" name="work[]" value="Design"> Design<br>
  <input type="checkbox" name="work[]" value="Email Design"> Email Design<br>
  <input type="submit" name="submit" value="Submit">
</form>

</body>
</html>