This core function looks like it would do the job:
# sends a message to a user's message box
function sendAlert($type, $to, $from, $subject, $msg, $private= 0) {
...
}
So inside a snippet, it should be as simple as..
$modx->sendAlert($type, $to, $from, $subject, $msg, $private);
Now, if you’re programming your own snippet, that’s great, but the question is: what are those parameters all about?
$type - I think you want this to be the string "Message" (maybe it can take other values, but I’m not sure what they are)
$to - can be the id of the user or the username
$from - can be the id of the user or the username
$subject - text of subject line
$msg - text of message
$private - should be 1 for a private message (not sure how to send messages to a group or to everyone)
If you’re not incorporating this into some snippet you’re working on, and you just want a snippet who’s only function is to send a message to a user, then you could do this:
Make a new snippet, let’s call it "SendMessage":
<?php
/**
* SendMessage 0.1
* Send a private message to a user
*/
$modx->sendAlert("Message", $to, $from, $subject, $msg, 1);
return '';
?>
And your snippet call could look like this:
[[SendMessage? &to=`user1` &from=`1` &subject=`test subject` &msg=`test message` ]]
(I set the from user to 1 because that should always be the id of the default admin user.)
I haven’t tried this out.. beware!!