drupal_mail to users selected from database In my Drupal 7 site I use custom tableselect form to manage some events. User can review profiles of people who applied for event and approve their participation. I want to send them email notification via drupal_mail on form submission. I have implemented hook_form_submit and added following code

foreach ($values as $key =&gt; $value){

    $sql = db_select('users', 'u');
    $sql-&gt; fields('u', array('mail'));
    $sql-&gt; condition('uid', $value['uid']);
    $mail = $sql-&gt;execute();
    }
    foreach($mail as $m){
    dsm($m);
    drupal_mail('event_manager','event_approved', $m, language_default());
    }


But in this case I have an error :


  Warning: explode() expects parameter 2 to be string, object given in
  SmtpMailSystem->mail()


How can I fix the code to make it work?
On a first glance, it's because you are passing the whole object instead of the email address. Try this:

  $sql = db_select('users', 'u');
  $sql-&gt; fields('u', array('mail'));
  $sql-&gt; condition('uid', $value['uid']);
  $mail = $sql-&gt;execute();
}
foreach($mail as $m){
  dsm($m);
  drupal_mail('event_manager','event_approved', $m-&gt;mail, language_default());
}