0

我正在尝试编写一个脚本,该脚本将允许我仅包含用户选择的那些复选框,然后将它们邮寄给我到相应的电子邮件地址。

4

2 回答 2

1
$message = "<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Something</title>
</head>
<body>


    <strong>Name</strong> : $name <br />
    PHONE : $phone <br />
    Company : $company<br />
    Selected options:<br />" .

 (isset($_POST['cb2']) ? 'Add me to your email list for updates<br>' : '') . 
 (isset($_POST['cb3']) ? 'Contact me regarding partnership<br>' : '') . 
 (isset($_POST['cb4']) ? 'Others<br>' : '') .
 (!isset($_POST['cb1'] &&
  !isset($_POST['cb2'] &&
  !isset($_POST['cb3'] &&
  !isset($_POST['cb4'] ? "None selected<br>" : "") .
    "Comments/Questions:<br />
    <hr />
    $mess
    <br />

</body>
</html>";
于 2012-04-21T12:55:21.333 回答
0

无论如何,浏览器只会发送选中的复选框。所以有如下内容:

<form action="index.php" method="POST">
    <label><input type="checkbox" value="Value of checkbox one" name="check[]"> Label for checkbox one</label>
    <label><input type="checkbox" value="Value of checkbox two" name="check[]"> Label for checkbox two</label>
    <label><input type="checkbox" value="Value of checkbox three" name="check[]"> Label for checkbox three</label>
    <label><input type="checkbox" value="Value of checkbox four" name="check[]"> Label for checkbox four</label>

    <button type="submit">Go</button>
</form>

然后在 PHP 中,$_POST["check"]将包含所有选定值的数组。

于 2012-04-21T12:57:24.560 回答