Reputation: 13492
Im trying to email a list of checkbox values using wp_mail
the result of my code IS sending the email
but the value returns as an array.. I understand why, but I am not sure how to breakdown the array, I dont see how I can implement a foreach here.
PHP:
//checkmarks post variable
$checks = $_POST['personalization_result'];
//php mailer variables
$to = get_option('admin_email');
$subject = "Someone sent a message from ".get_bloginfo('name');
$headers = 'From: '. $email . "rn" .
$sent = wp_mail($to, $subject, $checks, $headers);
HTML:
<form action="<?php the_permalink(); ?>" method="post">
<input type="hidden" name="submitted" value="1">
<input type="submit">
<li class="option table selected">
<div class="option-checkbox">
<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">
</div>
</div>
</li>
<li class="option table selected">
<div class="option-checkbox">
<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">
</div>
</div>
</li>
</form>
Upvotes: 1
Views: 417
Reputation: 6356
Before you call the wp_mail
function, you need to process your $checks
variable and turn it into a string, e.g.:
$checks = $_POST['personalization_result'];
$checkString = ''
foreach ($checks as $k=>$v) {
//some code to build up $checkString
}
You'd then obviously have to use $checkString
instead of $checks
in your wp_mail
call . . .
Alternatively, if you don't care about the keys, you could do something like:
$sent = wp_mail($to, $subject, implode("|",$checks), $headers);
Then you'd end up with something like "0|1"
Upvotes: 1