我不是一个PHP人,所以请原谅我,如果这是基本的东西。
以下是HTML页面上的三个复选框:
<INPUT TYPE="CHECKBOX" NAME="box[]" CLASS="box[]" VALUE="Communication Products Catalog">
<INPUT TYPE="CHECKBOX" NAME="box[]" CLASS="box[]" VALUE="Optics Catalog">
<INPUT TYPE="CHECKBOX" NAME="box[]" CLASS="box[]" VALUE="Systems Products Catalog">
当我点击提交时,我有一个php脚本,它只是抓取所有字段的值,将它们抛入变量然后我使用mail函数发送它。
这是我在php脚本中从表单中提取值的地方:
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$company = $_REQUEST['company'] ;
$email = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'] ;
$addr = $_REQUEST['addr'] ;
$city = $_REQUEST['city'] ;
$state = $_REQUEST['state'] ;
$zip = $_REQUEST['zip'] ;
$catalogsa = $_REQUEST['box'] ;
$catalogs = print_r( $catalogsa, true );
最后我“编译”构成电子邮件正文的$ msg var:
$msg = "First Name:\t$firstname\r";
$msg .= "Last Name:\t$lastname\r";
$msg .= "Company:\t$company\r";
$msg .= "Email:\t\t$email\r";
$msg .= "Phone:\t\t$phone\r";
$msg .= "Address:\t$addr\r";
$msg .= "City:\t\t$city\r";
$msg .= "State:\t\t$state\r";
$msg .= "Zip Code:\t$zip\r\r";
$msg .= "Catalogs:\r$catalogs\r";
所有这些都有效,电子邮件的正文只包含CHECKED框的值。 但这就是我收到电子邮件时的样子......
First Name: ME
Last Name: MYSELF
Company: AND I INC
Email: NONE@NONE.COM
Phone: 111-111-1111
Address: 222 SOME ST
City: SOME TOWN
State: NY
Zip Code: 11777
Catalogs:
Array
(
[0] => Communication Products Catalog
[1] => Systems Products Catalog
)
我正在寻找一种方法来清理$ catalogs变量,所以它看起来像:
Communication Products Catalog
Systems Products Catalog
提前致谢,
肯尼
答案 0 :(得分:1)
删除此行
$catalogs = print_r( $catalogsa, true );
然后做
$msg .= "Catalogs:\r";
foreach($catalogsa as $catalog)
{
$msg .= $catalog . "\r";
}
答案 1 :(得分:0)
可能这可以帮到你
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$company = $_REQUEST['company'] ;
$email = $_REQUEST['email'] ;
$phone = $_REQUEST['phone'] ;
$addr = $_REQUEST['addr'] ;
$city = $_REQUEST['city'] ;
$state = $_REQUEST['state'] ;
$zip = $_REQUEST['zip'] ;
$catalogsa = $_REQUEST['box'] ;
if(sizeof($catalogsa)>0){
$catalogs = implode(",",$catalogsa);
}
您可以使用逗号(,)或新行(“&lt; br /&gt;”)。如果它能解决您的问题,请告诉我。
答案 2 :(得分:0)
$msg .= "Catalogs:";
foreach ($catalogsa as $catalog){
$msg .= $catalog."\r";
}
答案 3 :(得分:0)
删除$msg .= "Catalogs:\r$catalogs\r";
和$catalogs = print_r($catalogsa, true);
尝试:
foreach($catalogsa as $catalog) {
$msg .= "Catalog:\r$catalog\r";
}
所以它会解决这个问题:
Catalog: Communication Products Catalog
Catalog: Systems Products Catalog