HowTo: Show Send Privatemsg to Author Form on an Author's Node

Last updated on
30 April 2025

This code by Gastonia and ul71m0 allows you to show the "send privatemsg" form for the node author on the node page.

The original discussion can be found here.

<?php
global $user;
if ($user->uid) {
    module_load_include('pages.inc','privatemsg');
    $recipients = $node->uid;
    print "<div>Contact " . $node->name ."  about this post.</div>";
    $subject = $node->title ." question.";
    $form = drupal_get_form('privatemsg_new', $recipients, $subject);
    // Setup destination parameter to be equal to current page.
    $form['#action'] = url('messages/new/'. $node->uid, array ('query' => drupal_get_destination()));
    print drupal_render($form);
    drupal_set_title($node->title);
} else {
    print "<div>Please login to contact this seller.</div>";
}
?>

Help improve this page

Page status: Not set

You can: