我是 php 的新手。我想在选择表单时在电子邮件中发布多个复选框值。只有最后一个选中的选项会在电子邮件中通过,即使它们都在表单中被选中。我为此尝试了许多解决方案,但似乎找不到适合我的解决方案。
我究竟做错了什么?
HTML:
<input type="checkbox" name="product-types-owned[]" value="Cast_Iron" />
<input type="checkbox" name="product-types-owned[]" value="Braisers" />
<input type="checkbox" name="product-types-owned[]" value="Ovens" />
<input type="checkbox" name="product-types-owned[]" value="Skillet" />
php:
$sendto = "email@email.com";
$usermail = $_POST['Email'];
$firstname = nl2br($_POST['First_name']);
$lastname = nl2br($_POST['Last_name']);
$address1 = nl2br($_POST['Address1']);
$address2 = nl2br($_POST['Address2']);
$city = nl2br($_POST['City']);
$state = nl2br($_POST['State']);
$zip = nl2br($_POST['Zip_Code']);
$phone = nl2br($_POST['Telephone']);
$ownership = nl2br($_POST['product-types-owned']);
$subject = "Product Registration";
$headers = "From: " . strip_tags($usermail) . "\r\n";
$headers .= "Reply-To: ". strip_tags($usermail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>Product Registration</h2>\r\n";
$msg .= "<p><strong>Sent by:</strong> ".$usermail."</p>\r\n";
$msg .= "<p><strong>First Name:</strong> ".$firstname."</p>\r\n";
$msg .= "<p><strong>Last Name:</strong> ".$lastname."</p>\r\n";
$msg .= "<p><strong>Address:</strong> ".$address1."</p>\r\n";
$msg .= "<p><strong>Address Line 2:</strong> ".$address2."</p>\r\n";
$msg .= "<p><strong>State:</strong> ".$state."</p>\r\n";
$msg .= "<p><strong>Zip:</strong> ".$zip."</p>\r\n";
$msg .= "<p><strong>Telephone:</strong> ".$phone."</p>\r\n";
$msg .= "<p><strong>Products Own or Intend to Own:</strong> ".$ownership."</p>\r\n";
$msg .= "</body></html>";
我已经尝试过这里的解决方案以及更改
$ownership = nl2br($_POST['product-types-owned']);
至
$ownership = nl2br(implode(',', $_POST['product-types-owned']));
我收到一个错误:Warning: implode() [function.implode]: Invalid arguments pass in /home/content/99/11039499/html/scripts/warranty.php 在第 24 行
请帮忙,我很沮丧。