1 contact.module | contact_mail($key, &$message, $params) |
Implements hook_mail().
File
- core/
modules/ contact/ contact.module, line 247 - Enables the use of personal and site-wide contact forms.
Code
function contact_mail($key, &$message, $params) {
$language = $message['language'];
$variables = array(
'!site-name' => config_get_translated('system.core', 'site_name', array(), array('langcode' => $language->langcode)),
'!subject' => $params['subject'],
'!category' => isset($params['category']['category']) ? $params['category']['category'] : '',
'!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)),
'!sender-name' => user_format_name($params['sender']),
'!sender-phone' => !empty($params['phone']) ? $params['phone'] : '',
'!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, array('langcode' => $language->langcode));
$message['body'][] = t("!sender-name (!sender-url) sent a message using the contact form at !form-url.", $variables, array('langcode' => $language->langcode));
if (!empty($params['phone'])) {
$message['body'][] = t("!sender-name provided a phone number: !sender-phone", $variables, array('langcode' => $language->langcode));
}
$message['body'][] = $params['message'];
break;
case 'page_autoreply':
$message['subject'] .= t('[!category] !subject', $variables, array('langcode' => $language->langcode));
$message['body'][] = $params['category']['reply'];
break;
case 'user_mail':
case 'user_copy':
$variables += array(
'!recipient-name' => user_format_name($params['recipient']),
'!recipient-edit-url' => url('user/' . $params['recipient']->uid . '/edit', array('absolute' => TRUE, 'language' => $language)),
);
$message['subject'] .= t('[!site-name] !subject', $variables, array('langcode' => $language->langcode));
$message['body'][] = t('Hello !recipient-name,', $variables, array('langcode' => $language->langcode));
$message['body'][] = t("!sender-name (!sender-url) has sent you a message via your contact form (!form-url) at !site-name.", $variables, array('langcode' => $language->langcode));
$message['body'][] = t("If you don't want to receive such emails, you can change your settings at !recipient-edit-url.", $variables, array('langcode' => $language->langcode));
if (!empty($params['phone'])) {
$message['body'][] = t("!sender-name provided a phone number: !sender-phone", $variables, array('langcode' => $language->langcode));
}
$message['body'][] = t('Message:', array(), array('langcode' => $language->langcode));
$message['body'][] = $params['message'];
break;
}
}