1

I'm facing an issue which is quite boring since the result displayed into Devel's PHP executer differs from the results of the Custom PHP code. What I want to do is sending private messages (thanks to privatemsg module) to certain users that I can't select with privatemsg Rules integration.

To send a new private_msg, we have to use the function "privatemsg_new_thread($recipients, $subject, $body)".

So I have to write a custom PHP code which is (I made it very simple) ; this one works in Devel but not in Rules.

$recipients = array(user_load(1));
$subject = 'hello';
$body = 'ok';
privatemsg_new_thread($recipients, $subject, $body);

When i write this ; it works with both modules

privatemsg_new_thread(array(user_load(1)), 'hello', 'ok');

Is there a problem with loading variables or sth ? And i don't have any error log...

Any help would be highly appreciated !

Thanks in advance

5
  • Not actually an answer to your question, but Privatemsg 6.x-2.x has built-in rules integration, with actions to send new messages and reply to existing ones. So, no custom PHP code required. – Berdir Oct 6 '11 at 1:58
  • Hey ! Thank you for answer ! Indeed, I know that but the thing is that with the built-in rules integration, we are not that free to select the recipients of the mail ; this is what i wanted to do :-) – jozi Oct 6 '11 at 10:29
  • Sure you can! You can send a message to any user you want. You just need to add a load user action first, where you can specify a hardcoded uid or something token based. – Berdir Oct 6 '11 at 12:03
  • Actually, I want to select all the users of a certain role ! I have finally suceeded by deleting and creating a new rule with the same PHP code ; I guess there must be a bug in there ! – jozi Oct 6 '11 at 16:55
  • FYI: The 7.x versions of Privatemsg also have a "send to role" rules action, but this hasn't been backported yet to 6.x-2.x. However, Privatemsg 6.x-2.x does allow sending messages to roles, when using a recipient object like this: $recipient = new stdClass(); $recipient->rid = $rid; $recipient->type = 'role'; (the privatemsg_roles module needs to be enabled). – Berdir Oct 7 '11 at 2:19
0

I have finally suceeded by deleting and creating a new rule with the same PHP code ; I guess there must be a bug in there !

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.