我已經設置了聯繫表單,並將其設置爲通過電子郵件將回復發送給電子郵件帳戶。表單的一部分是一系列複選框,我需要將這些複選框顯示在電子郵件中作爲列表。這是我下面的代碼,它現在返回'Array'而不是複選框的值。有什麼建議麼?如何通過PHP從HTML表單發送多個複選框響應?
HTML:
<h3>Service required:</h3>
<input type="text" id="name" name="name" placeholder="Name" required />
<input type="email" id="email" name="email" placeholder="Email" required />
<input class="check-box styled" type="checkbox" name="service[]" value="Service/repairs" /><label> Service/repairs</label>
<input class="check-box styled" type="checkbox" name="service[]" value="MOT" /><label> MOT</label>
<input class="check-box styled" type="checkbox" name="service[]" value="Cars for sale" /><label> Cars for sale</label>
這裏的PHP:
<?php
if (isset($_POST['service'])) {
$service = $_POST['service'];
// $service is an array of selected values
}
$formcontent= "From: $name \n Service(s) required: $service \n";
$recipient = "[email protected]";
$subject = "You have a new message from $name";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! We will get back to you as soon as we can.";
?>
感謝,
傑森
你需要通過你的服務陣列使用foreach – 2012-08-16 14:44:16