简体   繁体   中英

How to update database for the checkbox selected id's and send mail to respective email addresses

I want to send welcome mail to all users whose id gets status 1. I have achieved setting status 1 to those users who are being selected via checkbox but can't figure out how to send email to all who are checked. A suggestion would be helpful.

Here is my code for the same, do let me know what else I need to add for taking 'email' into variable '$check' and send mail.

 <td><input type="checkbox" name="all_check[]" <?php echo $disabled ;?> value= "<?php echo $row['id']; ?>"class="checkbox" id="status" ></td>
                      <input type="hidden" value="<?php echo $row['id']; ?>" name="user_id" id="user_id" >

And, code where I am setting status=1 for the selected users,

                <?php
if(!empty($_POST['all_check'])) {
    foreach($_POST['all_check'] as $check) {
          $update_status= mysql_query("UPDATE tbl_user SET status = '1' WHERE id = $check" );  
  }
}
?>

Thanks in advance.

Here look at the code may it will be give you some Idea.

if(!empty($_POST['all_check'])) {
    foreach($_POST['all_check'] as $check) {
    $update_status= mysql_query("UPDATE tbl_user SET status = '1' WHERE id = $check" );  
     $query=mysql_query("Select email From tbl_user where WHERE id=$check");
     if(mysql_num_rows($query)>0){
     $row=mysql_fetch_array($query);
     mail( $row['email'],"Welcome ","Welcome Message");
     }
  }

like this you have to pass two different query for updating and selecting operations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM