Privatemsg allows Drupal users sending message to each other. It is a must-have feature of community oriented websites. The module includes all necessary features including inbox, outbox, user block list etc. In my case, i want to render the send message form on the user profile page. So i created a block which generate the send message form by PHP code and attached it to the user profile page. Here you are.
<?php // Load the module module_load_include('pages.inc','privatemsg'); // We could get the user id from arg(1) becoz this block is shown in profile page. $recipients = array(user_load(arg(1))); $subject = 'Hello ' . $recipients->name; print drupal_render(drupal_get_form('privatemsg_new', arg(1), $subject)); // Restore the page title drupal_set_title($recipients->name); ?>
Please note that drupal_get_form() returns a render array in Drupal 7, you need to use drupal_render() to convert it to a string that you can print. And i also need to reset the title to username becoz the privatemsg_new form will override the page title.