已经使用 PHP 构建了一个功能表单,但是我有一个包含 5 个选项的复选框(可以选择超过 1 个),但是电子邮件中只显示了 1 个选项。
HTML:
<label class="radio"><input type="checkbox" name="service" value="Web Design" />Web Design</label>
<label class="radio"><input type="checkbox" name="service" value="Graphic Design" />Graphic Design</label>
<label class="radio"><input type="checkbox" name="service" value="Brand Identity" />Brand Identity</label>
<label class="radio"><input type="checkbox" name="service" value="Online Marketing" />Online Marketing</label>
<label class="radio"><input type="checkbox" name="service" value="Other" />Other</label>
PHP: ($service)
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$website = $_POST['website'];
$service = $_POST['service'];
$description = $_POST['description'];
$inspiration = $_POST['inspiration'];
$budget = $_POST['budget'];
$deadline = $_POST['deadline'];
$formcontent=" From: $name \n Email: $email \n Phone: $phone \n Website: $website \n\n service: $service \n budget: $budget \n deadline: $deadline \n\n description: $description \n\n inspiration: $inspiration ";
$recipient = "myemail@gmail.com";
$subject = "Contact form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You, your information has been received.";
?>
最佳答案
如果您有多个同名元素,那么您将只能读取其中一个,除非您使用数组语法 []
例如name=service[]
那么您将收到 $_POST['service'] 作为包含您所有服务的数组。您可以使用 implode将其转换为字符串。
$service = implode(' ', $_POST['service']);
关于php - PHP 表单上的多个复选框选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12907283/