我从表单中获取数据并使用电子邮件发送它wp_mail
,因为有多个数据(所有复选框数据)显然需要一个 foreach。
我无法在 foreach 中获取数据并在语句之外使用它。
//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>
对不起,如果这有点笨拙,但这是我通过询问来学习的方式。