Form submission handler for contact_site_form().
function contact_site_form_submit($form, &$form_state) {
global $user;
$language_interface = language(LANGUAGE_TYPE_INTERFACE);
$values = $form_state['values'];
$values['sender'] = $user;
$values['sender']->name = $values['name'];
$values['sender']->mail = $values['mail'];
$values['category'] = entity_load('contact_category', $values['category']);
if (!$user->uid) {
$values['sender']->name .= ' (' . t('not verified') . ')';
// Save the anonymous user information to a cookie for reuse.
user_cookie_save(array_intersect_key($values, array_flip(array(
'name',
'mail',
))));
}
// Get the to and from e-mail addresses.
$to = implode(', ', $values['category']->recipients);
$from = $values['sender']->mail;
// Send the e-mail to the recipients using the site default language.
drupal_mail('contact', 'page_mail', $to, language_default()->langcode, $values, $from);
// If the user requests it, send a copy using the current language.
if ($values['copy']) {
drupal_mail('contact', 'page_copy', $from, $language_interface->langcode, $values, $from);
}
// Send an auto-reply if necessary using the current language.
if ($values['category']->reply) {
drupal_mail('contact', 'page_autoreply', $from, $language_interface->langcode, $values, $to);
}
drupal_container()
->get('flood')
->register('contact', config('contact.settings')
->get('flood.interval'));
watchdog('mail', '%sender-name (@sender-from) sent an e-mail regarding %category.', array(
'%sender-name' => $values['name'],
'@sender-from' => $from,
'%category' => $values['category']
->label(),
));
// Jump to home page rather than back to contact page to avoid
// contradictory messages if flood control has been activated.
drupal_set_message(t('Your message has been sent.'));
$form_state['redirect'] = '';
}