Last updated June 28, 2011. Created by Dublin Drupaller on June 28, 2011.
Log in to edit this page.

Introduction

I created the following snippet recently for a project where the default message text If you don't want to receive such e-mails...etc. and link to change a users personal contact form settings needed to be changed. Thought it might be of use to others.

Step 1 of 2

Copy the following snippet into a custom projectname_overrides.module and modify projectname to suit.

If you don't already have a projectname_overrides.module setup for your project. See below for a simple module .info file you can use.

<?php
/**
*  Overriding the default user contact email
*/
function projectname_overrides_mail_alter(&$message) {
  if (
$message['id'] == 'contact_user_mail') {
    
$argie = arg(1); //no $params available so pull the users UID from the arg
    
$message['body'][2] = t("If you don't want to receive such e-mails, you can change your Personal Contact Settings at the following link: !url.", array('!url' => url("user/$argie/edit", array('absolute' => TRUE, 'language' => $language))), $language->language); // this is specific for the drupal 6.x version of contact module. you may need to change the array key from 2 to something else if you are using a different version that changes the way the email body is put together.
 
}
}
?>

Step 2 of 2

Enable the module. When you now send a message using a personal contact form, the text now reads:

If you don't want to receive such e-mails, you can change your Personal
Contact Settings at the following link:
http://www.example.com/users/7708/edit

Where 7708 is obviously the recipients user id.

projectname_overrides.info file

Here's a projectname_overrides.info file you can copy and use if you don't already have a custom projectname_overrides.module set up.

; $Id$
name = Custom Overrides
description = Custom overrides module
core = 6.x

Notes

  • Assumes clean urls are enabled
  • Tested by Dublin Drupaller june 2011 with drupal 6.x and pressflow
  • Please add a child page to this handbook page if you find an improvement or more efficient way of doing this
  • Ideally the core contact.module should be patched with an admin settings page form that allows admins to customise the default message text via the drupal admin gui

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

In order to change other parts of the body you might need to include:

$user = $message['params']['user'];
   $account = $message['params']['account'];

CTI Digital

Anyone experience in using this in Drupal 7? And should I use the module "module builder" for it?