Multiple Checkboxes

浪尽此生 提交于 2019-12-13 09:39:49

问题


Found this on the internet. How can I put this output into an email? Normally I use

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

I would like the output of this code into my $email_body. Is this posible?

<?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:


$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] . " ";
    }
  }
?>


来源:https://stackoverflow.com/questions/45510682/multiple-checkboxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!