将多个复选框值发布到php电子邮件中 [英] Post multiple checkbox values into php email
问题描述
我是php的全新。我想在选择表单时在表单的电子邮件中发布多个复选框值。只有检查的最后一个选项是通过电子邮件,即使他们都在表单中选择。我已经尝试了许多解决方案,我发现了这一点,似乎找不到一个为我工作。
I am brand new to php. I would like to post multiple checkbox values in an email from a form when they are selected. Only the last option checked is coming through in the email, even if they are all selected in the form. I have tried many solutions I found on for this and can't seem to find one that works for me.
我做错了什么?
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($_POST['product-types-owned']);
到
$ ownership = nl2br(implode(',',$ _POST ['product-types-所有的']));
$ownership = nl2br(implode(',', $_POST['product-types-owned']));
并且我得到一个错误:Warning:implode()[function.implode]:无效的参数传递在/ home / content / 99/11039499 /html/scripts/warranty.php第24行
and I get an error: Warning: implode() [function.implode]: Invalid arguments passed in /home/content/99/11039499/html/scripts/warranty.php on line 24
请帮助,我很失望。
推荐答案
$ownership = nl2br($_POST['product-types-owned']);
产品类型拥有
是所选复选框值的数组。在你做任何事情之前,你需要打破它:
product-types-owned
is going to be an array of the checkbox values that were selected. You'll need to implode that before you do anything else:
$ownership = nl2br(implode(',', $_POST['product-types-owned']));
现在你试图在数组上使用nl2br, nl2br需要一个字符串,所以php将类型转换为其默认字符串表示形式,这是字面上的字 Array
。
Right now you're trying to nl2br on an array, which won't work. nl2br expects a string, so php will type cast the array into its default string representation, which is literally the word Array
.
这篇关于将多个复选框值发布到php电子邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!