Hello together,

with the following code-snippet I tried to send email, if a result-field of a view has a special value. I used Custom php in the Action-Field:

$display = 'Rules';
$view = views_get_view('gegen_berstellung_order_mit_anzahl_klicks');
$view -> set_display($display);
$view->execute();
foreach($view->result as $r=>$result){
  if(($result->php_3)=='0') {
   $mail = $result->mail;
   $to = $mail;
   $settings = array();
   $settings['to'] = $to;
   $settings['subject'] = "email subject";
   $settings['message'] = "message body";
   rules_action_mail($settings);
    }
  else {
    return "do nothing";
  }
}

It sends no email to no one. Into the view, the mail is not linked to anything. What is my mistake in here. It would be very nice, if someone can help.

Thanks a lot in advance.

Comments

tr’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)
Issue tags: -views, -rules, -activation email

Well, it's not clear what you're doing with the code and where it appears. I guess that's probably executed from within Views ...

If you're just trying to send mail programmatically, you don't need Rules, you should just use drupal_mail(). If you are trying to invoke a Rules action from some other piece of code, this is not the way to do it - actions don't exist outside of a Rule, so you can't just call the action implementation directly. But you can create a component to hold your actions then execute that component in your code - that's described in the documentation.