HTML of form is given below

 for($i=$start;$i < $end ;++$i)
     $user_info = get_users($userId); 
     echo"<tr class='iedit alternate'>
     <td  class='name column-name' style='border:1px solid #DBDBDB;padding-left:13px;'><input type='checkbox' id='haet_mail_test_address' name='ckboxs[]'  value='".$emails[$i]['user_email']."'>&nbsp;".$emails[$i]['user_email']."</td>";
      echo "<td  class='name column-name' style='border:1px solid #DBDBDB;'> ".$user_info->user_login."</td>";
      echo "</tr>";
<button class="button-primary" id="haet_mail_test_submit" name="submit" type="submit">Send Email</button>
<div id="haet_mail_test_sent" class="haet-mail-dialog" title="<?php _e('Email sent','wp-html-mail'); ?>">
<?php _e('Your message has been sent.','wp-html-mail'); ?>

below my Javascript code

    var checkbox = $('#haet_mail_test_address').val();
    $.post(ajaxurl, { 'action':'haet_mail_send_test', 'checkbox':checkbox} , function(response) {
        $( "#haet_mail_test_sent" ).dialog({
            dialogClass: "no-close",
            modal: true,
            buttons: [
                    text: "OK",
                    click: function() {
                        $( this ).dialog( "close" );

AJAX function is given below

function send_test() {
    $email= $_POST['checkbox'];
    echo $email;        
    wp_mail( $email, ''.$email.'');

I am new on Wordpress so how I can send the checkbox values to wp_mail


First you need to add a class for all checkbox as having same id for multiple items is not recommended

<input type='checkbox' class="new_class" id='haet_mail_test_address' name='ckboxs[]'  value='".$emails[$i]['user_email']."'>

Now we to change the way you are getting the values from checkbox


var checkbox = $('#haet_mail_test_address').val();


var checkbox = $(".new_class:checkbox:checked").map(function(){
  return $(this).val();

console.log(checkbox); // check if you are getting the values here

Now in "checkbox" you will get an array of selected checkbox values. Now you can pass it to the ajax function as data

  • in my email subject the value are array is showing how to remove this – Shashikant Kalawatia Jul 6 '18 at 6:08
  • What are you really trying to implement? How you want your email to be like?? – Unnikrishnan R Jul 6 '18 at 6:11
  • I want to send bulk email through my custom plugin – Shashikant Kalawatia Jul 6 '18 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.