多个复选框

时间:2017-08-04 15:35:06

标签: php html forms email checkbox

在互联网上找到这个。如何将此输出放入电子邮件中? 通常我用

$name = $_POST['name'];
$email_body = "$name";

我希望将此代码输出到我的$ email_body中。 这是可能的吗?

<?php
  $aDoor = $_POST['formDoor'];
  if(empty($aDoor)) 
  {
    echo("You didn't select any buildings.");
  } 
  else 
  {
    $N = count($aDoor);

    echo("You selected $N door(s): ");
    for($i=0; $i < $N; $i++)
    {
      echo($aDoor[$i] . " ");
    }
  }
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="style.css">
   <body>
   <form action="test.php" method="post">

    Which buildings do you want access to?<br />
    <input type="checkbox" name="formDoor[]" value="A" />Acorn Building<br />
    <input type="checkbox" name="formDoor[]" value="B" />Brown Hall<br />
    <input type="checkbox" name="formDoor[]" value="C" />Carnegie Complex<br />
    <input type="checkbox" name="formDoor[]" value="D" />Drake Commons<br />
    <input type="checkbox" name="formDoor[]" value="E" />Elliot House

    <input type="submit" name="formSubmit" value="Submit" />

  </form>
 </body>

1 个答案:

答案 0 :(得分:0)

$name = $_POST['name'];
$email_body ='';

<?php
  $aDoor = $_POST['formDoor'];
  if(empty($aDoor)) 
  {
    $email_body = "You didn't select any buildings.";
  } 
  else 
  {
    $N = count($aDoor);

    $email_body .= "You selected $N door(s): ";
    for($i=0; $i < $N; $i++)
    {
    $email_body .=  $aDoor[$i] . " ";
    }
  }
?>