I created this for my site (as a replacement for nasty hack I'm running all the time since 4.7.x times), and I think it might be a nice extension to the privatemsg project. I'm attaching a ready module (AFAICT), that works fine for me. I'm not going to maintain own projects, for variety of reasons, so take it or leave it...

Basically, it provides a replacement for the part of core Contact module, that is not covered by Privatemsg itself yet, so that Contact module may be disabled entirely now.

The Privatemsg module in fact replaces core Contact module, so it doesn't make much sense to run both these modules, having both mail-based and privatemsg-based contacts to users (for instance: a 'Contact' tab, plus 'Send message to this user' link, both on user profile page). But the Contact module may be still needed for it's second part - the site-wide contact form. Such a form makes a lot of sense with Privatemsg too, providing a kind of "official" contact to the staff/webmaster/support/whatever. For logged in users, it just simplifies the process of giving feedback, as the user don't need to research on possible usernames of staff members, and who is the proper recipient for a certain topic. For anonymous users, the site-wide contact form is the only way to send all these messages like "Help, I can't login!", "My account got blocked - WTF?", "You have a typo here and there!" etc. etc. Simply - the site-wide contact form is still needed.

In the other hand, the core site-wide contact form based on e-mail is maybe the most problematic part of the Conatct module. E-mails are getting lost, not passing thru spam filters, and random anonymous visitors are not giving their feedback twice. All junk submitted to the form is forwarded via mail, causing the hosting provider to recognize the outgoing mails as spam, and blocking the hosting account. (Really happened on my site! That's why I took this new route initially.) This is all easily fixed by routing the messages locally to privatemsg, and we get rid of Contact module at the same time.

The attached module is basically a clone of core Contact module, but modified "quite a bit". The functionality is mostly the same (minus "send me a copy", and auto-reply mail, which make no sense here), but the list of e-mail recipients is changed into a list of Drupal users. Also, name and e-mail address is only required for anonymous users, and gets embedded into message body (we don't have other place for it, and it's needed in a message sent by anonymous). If a logged-in user submits the contact form, the message is sent from his account as usual, apart from a short notice about the contact-form being added, and recipients pre-selected. Then, there's the problem of a message sent from anonymous user, which Privatemsg disallows on multiple places, so I suppose it's not wise to try and sneak uid=0 in (although it worked in my previous 5.x hack). So, I added a new setting - the user account, from which the anonymous feedback messages will be sent. This is ideally a dummy on-purpose created account like "no reply" or "anonymous feedback" etc., serving just as a stand-in for the sender field, and identifying these contact-form messages too. Default sender is user 1 (the only one we can assume is owned by webmaster/staff), but it may/should be re-configured.

Attaching the module as tar.gz archive, because rolling a patch against "nothing" makes no sense IMO.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Tally’s picture

Great module. I tested it and am using it on a production site.

I found one error for the case where there are multiple categories without a default category specified.

At line 65 of privatemsg_contact.pages.inc there is a 'not' that should not be used. I made the following change:

// Tally July 2009: there should not be a 'not' in next line - "Please choose" is to be displayed when no default
 -  if (!empty($default_category)) {
 +  if (empty($default_category)) {

The Please choose feature is important to me because I don't set a default category. That way, the automated comment spammers cannot send messages because the error message for not selecting a category stops them. This same technique keeps automated comment spammers from registering on my site.

Also, when I get messages, I want to know what category was selected. Contact messages for all categories go to one address. So, using severe overkill, I put the category name in front of the subject and I also added it to the body of the message.

I replaced lines 123-129 in the original privatemsg_contact.pages.inc file with the following code:

// Tally July 2009 - Get  category name
   $cat_id = $values['cid'];
   $result = db_query('SELECT category FROM {pm_contact} WHERE cid = %d', $cat_id);
   $category_name = db_fetch_object($result);
	
// Tally July 2009: Add category to subject line
   $values['subject'] = $category_name->category . ': ' . $values['subject'];

// Tally July 2009 - formatted text for presentation
   if (!$user->uid) {
   $body = t('Category: <strong>@category</strong><br />Sent via the site-wide contact form by anonymous user: <strong>@name</strong>. <br />Reply to: @mail', array('@category' => $category_name->category, '@name' => $values['name'], '@mail' => $values['mail'])) .' <hr /><br />';
   }
   else {
// Tally July 2009 - formatted text for presentation  
    $body = t('Category: <strong>') . $category_name->category . t('</strong><br />Sent via the site-wide contact form. <hr />');	
   }
   $body .= $values['message'];
NaheemSays’s picture

Does messaging.module provide such redirection? If so, I would push people their way - reduces duplication and stuff.

rburgundy’s picture

Can this sub-module be brought up to speed and possibly compatible with 6.x-2.x-dev? This is a great new feature!

Berdir’s picture

Version: 6.x-1.x-dev »
FileSize
5.83 KB

Re-rolled the module with a few modifications..
- Recipients are now stored as a string and looked up when sending messages with _privatemsg_parse_username(). That will allow easier integration with non-user recipients like roles. There is still a permission issue, though...
- It is now possible to define subject and body (both for authenticated and anon users) per category through the admin interface.

Note: There are database changes and there is no upgrade path. You have to uninstall (not simply disable) the module and install it again. No sent messages will be lost but you have to re-create your categories and the settings.

crea’s picture

Nice idea!.
I have one question: would it make sense to have an option to select between e-mail and pm transport for anonymous user requests ? That could make replying easier, compared to case when you receive pm first and then get notified by mail.

Berdir’s picture

FYI, I installed and configured the privatemsg_contact module at the newly installed demo site: http://demo.worldempire.ch, if someone wants to test it.

Berdir’s picture

Re-roll, a few (mostly permission related) bugs fixed, some string changes, for example, removed a "Please" ( That shouldn't be used according to the new UI text standards).

Oh, and, I backported some of the D7 contact.module tests.

BenK’s picture

Keeping track of this... Berdir, do you want me to test? It's a feature I hadn't really considered before. I mainly used the Webform module for a site contact form...

--Ben

EndEd’s picture

Subscribing and hopping it gets mollom compatible in the future.

weeksan’s picture

You're amazing thank you.

I've played a bit on your site, what would be amazing (if you're willing), is to walk people through how to set this up and use it, because I can't figure it out lol.

I enabled the permissions but can't seem to find where or how to integrate it.

Berdir’s picture

It works exactly the same like contact.module.

There is a contact form tab on the privatemsg settings which, you can add contact categories there.

See http://test.worldempire.ch/admin/settings/messages/contact (you need to be logged in as "admin")

Then you just have to enable the Privatemsg contact menu item. This is also described in the help block in above link.

joezine’s picture

Version: » 7.x-2.x-dev

hi,

privatemsg_contact has compatibility with drupal 7?

Berdir’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev

No, the patch is against 6.x-2.x.

pinkonomy’s picture

is there any though of porting this patch to drupal 7?
thanks

oadaeh’s picture

Status: Needs review » Closed (won't fix)

This issue is being closed because it is against a branch for a version of Drupal that is no longer supported.
If you feel that this issue is still valid, feel free to re-open and update it (and any possible patch) to work with the 7.x-1.x branch (bug fixes only) or the 7.x-2.x branch.
Thank you.