2

I am using the Private Message module as a way of contacting the author of a node.

I have the problem that the button that says "Send author a message" only appears on the node when the user is logged in. If the user is not logged in, then the button that appears is the one that says "Log in or register to be able to post comments" (or something like that)

What I want to achieve is that the user (not logged in) can see the "Send author a message" on the node. And when this user clicks on this button he will be taken to the login form first, and then, after login, the user gets redirected to type the message to the node author.

How can I achieve this?

  • Have you checked any permissions for this module? Without knowing much about your business modelor technical model do you want anonymous users to send messages through your site? – Rick Jul 18 '15 at 13:47
1

The Privatemsg module CANNOT be used for anonymous users ... Unless you are ready for some "tweaks" ... as detailed below.

I'm assuming your question is about D7, if it is for D6, you might consider using what's described in Issue # 490264. But it's worth reviewing that issue to get "an idea" about a possible work around ...

So how about D7? Issue # 554238 is about D7, and Comment #7 in it refers to the issue I mentioned above (which is for D6). However Comment #8 in that issue might be the solution. It contains this code sample:

<?php
$msg = "Hello there";
$source_tag = "from {$_SERVER['REMOTE_ADDR']}";
$result = privatemsg_new_thread( array(user_load(1)), "Browser visit {$source_tag}", $msg, array('author' => user_load(1)) );
// If you wanted to show an error, uncomment the following:
if (!isset( $result['success'] ) || !$result['success'])
{
  printf( "<p>Failed to send: %s</p>\n", $result['error'] );
}
?>

Apart from what is above, there is also the (way more) recent issue # 2231795. Comment #1 in it contains a code sample also. So if the above code doesn't fit (or work), consider this as an alternative.

So by using the Privatemsg module, and some tweaks (see above) you should be able to make it work somehow for anonymous users also

  • Thank you for the "thanks". Also, hope you don't mind I say so, but looking at your profile I noticed that you never visited the "tour" (link within "help", upper right). So you probably are not aware either of what's written in drupal.stackexchange.com/help/someone-answers ... – Pierre.Vriens Aug 5 '15 at 21:12
  • I will visit this section, no problems – Raidel Grimon Aug 5 '15 at 21:17

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.