从“;“已检查”;html框通过php发送电子邮件


Sending inquiries from "checked" html boxes to email through php

好吧,我在谷歌上搜索了又搜索了一些,我被卡住了。我对php的想法真的很陌生,但我终于让我的表单做了我想做的事情,只是当我把它发送到电子邮件时,它只显示我选中的一个框。我真的很讨厌寻求帮助,但事情已经过去了。

这是我的html:

<tr>
 <td valign="left"><p>Please check all items needed *</p>
   <p class="style2">(Default order will be one of each checked item unless otherwise indicated in the comments section.)</p>
 <td valign="top">
     <div align="left">
 <input type="checkbox" name="supplies[]" value="black_toner" /> Black Toner<br />
 <input type="checkbox" name="supplies[]" value="cyan_toner" /> Cyan Toner<br />
 <input type="checkbox" name="supplies[]" value="magenta_toner" /> Magenta Toner<br />
 <input type="checkbox" name="supplies[]" value="yellow_toner" /> Yellow Toner<br />
 <input type="checkbox" name="supplies[]" value="black_drum" /> Black Drum<br />
 <input type="checkbox" name="supplies[]" value="cyan_drum" /> Cyan Drum<br />
 <input type="checkbox" name="supplies[]" value="magenta_drum" /> Magenta Drum<br />
 <input type="checkbox" name="supplies[]" value="yellow_drum" /> Yellow Drum<br />
 <input type="checkbox" name="supplies[]" value="waste_toner" /> Waste Toner<br />
 <input type="checkbox" name="supplies[]" value="staples" /> Staples<br />
     </div>
   <td valign="top"> </td>
</tr>

这是我的php

 }
    $email_message = "Form details below.'n'n";
function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."'n";
$email_message .= "Last Name: ".clean_string($last_name)."'n";
$email_message .= "Company: ".clean_string($company)."'n";
$email_message .= "Location: ".clean_string($location)."'n";
$email_message .= "Machine Model: ".clean_string($machine_model)."'n";
$email_message .= "Supplies: ".clean_string($supplies)."'n";
$email_message .= "Email: ".clean_string($email)."'n";
$email_message .= "Telephone: ".clean_string($telephone)."'n";
$email_message .= "Comments: ".clean_string($comments)."'n";

// create email headers
$headers = 'From: '.$email_from."'r'n".
'Reply-To: '.$email_from."'r'n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

正如我所说,我已经尝试了我认为的一切,但显然出了问题。我需要在我的php/html中添加什么或更改什么才能从我的复选框中获得所有响应,而不仅仅是一个响应?如果有人有任何建议,我将不胜感激。(请尽可能具体,就像我说的,我是一个新手)谢谢!

您没有显示在哪里分配$supply,但它是一个数组。当你分配时试试这个。

$supplies = implode(',',$_POST['supplies']);

$supplies是一个数组,因为你把[]放在它的形式中。你必须使用函数内爆来分离它们:

$supplies = implode(",", $supplies);
$string = implode(", " $_POST['supplies']);

http://www.kavoir.com/2009/01/php-checkbox-array-in-form-handling-multiple-checkbox-values-in-an-array.html

1) 此HTML:

<input type="checkbox" name="tags[]" value="1" />
<input type="checkbox" name="tags[]" value="2" />
<input type="checkbox" name="tags[]" value="3" />
<input type="checkbox" name="tags[]" value="4" />

2) 。。。变成这个PHP:

print_r($_POST['tags']);
// output
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
)

3) 在您的情况下,如果您在表单中只检查了"黑色碳粉"answers"青色鼓",那么您应该在数组中返回的值只有"black_toner"answers"cyan_drum"。只需修改代码以处理您获得的值。

4) 我剪切/粘贴了您的表单,并设置了"action="一个调用"phpinfo()"的脚本。以下是phpinfo的结果,只检查black_toner和cyan_drum:

_POST["supplies"]
Array
(
    [0] => black_toner
    [1] => cyan_drum
)