1

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 => $value){

    $sql = db_select('users', 'u');
    $sql-> fields('u', array('mail'));
    $sql-> condition('uid', $value['uid']);
    $mail = $sql->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?

2 Answers 2

2

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-> fields('u', array('mail'));
  $sql-> condition('uid', $value['uid']);
  $mail = $sql->execute();
}
foreach($mail as $m){
  dsm($m);
  drupal_mail('event_manager','event_approved', $m->mail, language_default());
}
0
0

In drupal_mail() function the third parameter should be the email address to whom you want to send email to.So pass the email address of user instead of $m.

Your Answer

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

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