2012-04-21 28 views
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>"; 
+0

感謝代碼工作像一個魅力! – 2012-04-21 12:59:52

+0

最後一個問題假設如果沒有用戶正在檢查,那麼我應該在沒有發送任何代碼的情況下寫入什麼內容? – 2012-04-21 13:09:13

+0

更新了代碼 – 2012-04-21 13:11:43

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"]將包含所有選擇值的數組。