You are here

function contact_attach_mail in Contact Attach 6

Implementation of hook_mail().

File

./contact_attach.module, line 358
Allows attaching files to e-mails sent using the site-wide contact form.

Code

function contact_attach_mail($key, &$message, $params) {
  $language = $message['language'];
  switch ($key) {
    case 'contact_page_mail':
    case 'contact_page_copy':
      $contact = $params['contact'];
      $message['subject'] .= t('[!category] !subject', array(
        '!category' => $contact['category'],
        '!subject' => $params['subject'],
      ), $language->language);
      $message['body'][] = t("!name sent a message using the contact form at !form.", array(
        '!name' => $params['name'],
        '!form' => url($_GET['q'], array(
          'absolute' => TRUE,
          'language' => $language,
        )),
      ), $language->language);
      $message['body'][] = $params['message'];

      // Attachment processing begins here.
      $return_message = _contact_attach_process_attachments($message);
      if (!empty($return_message)) {
        $message['headers'] = $return_message['headers'];
        $message['body'] = $return_message['body'];
      }

      // Attachment processing ends here.
      break;
    case 'contact_page_autoreply':
      $contact = $params['contact'];
      $message['subject'] .= t('[!category] !subject', array(
        '!category' => $contact['category'],
        '!subject' => $params['subject'],
      ), $language->language);
      $message['body'][] = $contact['reply'];
      break;
    case 'contact_user_mail':
    case 'contact_user_copy':
      $user = $params['user'];
      $account = $params['account'];
      $message['subject'] .= '[' . variable_get('site_name', 'Drupal') . '] ' . $params['subject'];
      $message['body'][] = "{$account->name},";
      $message['body'][] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array(
        '!name' => $user->name,
        '!name-url' => url("user/{$user->uid}", array(
          'absolute' => TRUE,
          'language' => $language,
        )),
        '!form-url' => url($_GET['q'], array(
          'absolute' => TRUE,
          'language' => $language,
        )),
        '!site' => variable_get('site_name', 'Drupal'),
      ), $language->language);
      $message['body'][] = t("If you don't want to receive such e-mails, you can change your settings at !url.", array(
        '!url' => url("user/{$account->uid}", array(
          'absolute' => TRUE,
          'language' => $language,
        )),
      ), $language->language);
      $message['body'][] = t('Message:', NULL, $language->language);
      $message['body'][] = $params['message'];

      // Attachment processing begins here.
      $return_message = _contact_attach_process_attachments($message);
      if (!empty($return_message)) {
        $message['headers'] = $return_message['headers'];
        $message['body'] = $return_message['body'];
      }

      // Attachment processing ends here.
      break;
  }
}