Im从表单中获取数据并使用wp_mail对其进行电子邮件,因为存在多个数据(所有复选框数据),显然需要有一个预测。
我不能把我的头转到获取数据中,然后在语句之外使用它。
//My form data
$checks = $_POST['personalization_result'];
//Pass the foreach array into this variable and use this to mail
$checkString = '';
//For each checkbox data
foreach ($checks as $k => $v) {
var_dump ($v);
}
//Email the data
$sent = wp_mail($to, $subject, $checkString, $headers); //I have set up the other variables but its not necessary to add here just focused on $checkString表单片段
<form action="<?php the_permalink(); ?>" method="post">
<?php echo $checkString; ?>// Trying to see what the array is doing
<input type="hidden" name="submitted" value="1">
<p><input type="submit"></p>
<li class="option table selected">
<input type="hidden" value="0" name="personalization_result[memory_0]">
<input type="checkbox" value="1" name="personalization_result[memory_0]" id="personalization_result_memory_0" checked="checked">
</li>
<li class="option table selected">
<input type="hidden" value="0" name="personalization_result[memory_1]">
<input type="checkbox" value="1" name="personalization_result[memory_1]" id="personalization_result_memory_1" checked="checked">
</li>
我很抱歉,如果这是有点过分,但这是我如何通过询问学习。
发布于 2013-08-07 15:12:16
由于wp_mail的第三个参数message是一个字符串,所以我认为可以完全避免使用值作为数组获取值,并使用一些胶水将它们连接起来,而不是在$checks数组中循环。请尝试:
$checkValues = array_values($checks);
$checkString = implode(',', $checkValues); // This generates comma separated list of values.您可以在内爆函数调用中使用您喜欢的任何胶水(本例中的逗号),这取决于您希望如何显示.$checkValues。
https://stackoverflow.com/questions/18106971
复制相似问题