1

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>

1 Answer 1

1

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"

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer I am going to implement it now... After I posted this question I had to run somewhere... Ill post back with my result..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.