You are here

function contact_mail in Contact 6.2

Same name and namespace in other branches
  1. 7.2 contact.module \contact_mail()

Implements hook_mail().

File

./contact.module, line 171
Enables the use of personal and site-wide contact forms.

Code

function contact_mail($key, &$message, $params) {
  $language = $message['language'];
  $variables = array(
    '!site-name' => variable_get('site_name', 'Drupal'),
    '!subject' => $params['subject'],
    '!category' => isset($params['category']['category']) ? $params['category']['category'] : '',
    '!form-url' => url($_GET['q'], array(
      'absolute' => TRUE,
      'language' => $language,
    )),
    '!sender-name' => $params['sender']->name,
    '!sender-url' => $params['sender']->uid ? url('user/' . $params['sender']->uid, array(
      'absolute' => TRUE,
      'language' => $language,
    )) : $params['sender']->mail,
  );
  switch ($key) {
    case 'page_mail':
    case 'page_copy':
      $message['subject'] .= t('[!category] !subject', $variables);
      $message['body'][] = t("!sender-name (!sender-url) sent a message using the contact form at !form-url.", $variables);
      $message['body'][] = $params['message'];
      break;
    case 'page_autoreply':
      $message['subject'] .= t('[!category] !subject', $variables);
      $message['body'][] = $params['category']['reply'];
      break;
    case 'user_mail':
    case 'user_copy':
      $variables += array(
        '!recipient-name' => $params['recipient']->name,
        '!recipient-edit-url' => url('user/' . $params['recipient']->uid . '/edit', array(
          'absolute' => TRUE,
          'language' => $language,
        )),
      );
      $message['subject'] .= t('[!site-name] !subject', $variables);
      $message['body'][] = t('Hello !recipient-name,', $variables);
      $message['body'][] = t("!sender-name (!sender-url) has sent you a message via your contact form (!form-url) at !site-name.", $variables);
      $message['body'][] = t("If you don't want to receive such e-mails, you can change your settings at !recipient-edit-url.", $variables);
      $message['body'][] = t('Message:', array());
      $message['body'][] = $params['message'];
      break;
  }
}