仅邮寄已选中的复选框

时间:2012-04-21 12:51:00

标签: php

我正在尝试编写一个脚本,允许我只包含用户选择的复选框,然后将它们邮寄给我各自的电子邮件地址。

2 个答案:

答案 0 :(得分: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>";

答案 1 :(得分: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"]将包含所有选定值的数组。

相关问题