Use the cbNotification class to send emails and/or private messages. Example as follows to send a private message from another user or from the site itself (system).
API:
Code:
$notification = new cbNotification();
$notification->sendUserPMSmsg( TO_USER_ID, FROM_USER_ID, SUBJECT, MESSAGE, FROM_SYSTEM );
From User:
Code:
$notification = new cbNotification();
$notification->sendUserPMSmsg( 36, 49, null, 'Hello!' );
From System:
Code:
$notification = new cbNotification();
$notification->sendUserPMSmsg( 36, 0, null, 'Hello!', true );
SUBJECT isn't really used anymore, but you can set it if you want. It'll just be prepended to MESSAGE on send. FROM_SYSTEM accepts true/false with default false and makes the PM come from the site instead of any specific user.
Note CBs API needs to be loaded in before it can be used externally. The below explains how.
www.joomlapolis.com/documentation/279-community-builder/tutorials/18357-including-cb-api-for-usage-outside-of-cb