You are here

function contact_mail_page_submit in Contact 6.2

Form submission handler for contact_mail_page().

File

./contact.pages.inc, line 132
User page callbacks for the contact module.

Code

function contact_mail_page_submit($form, &$form_state) {
  global $user, $language;
  $values = $form_state['values'];
  $values['sender'] = $user;
  $values['sender']->name = $values['name'];
  $values['sender']->mail = $values['mail'];
  $values['category'] = contact_load($values['cid']);

  // Save the anonymous user information to a cookie for reuse.
  if (!$user->uid) {
    contact_cookie_save($values);
  }

  // Get the to and from e-mail addresses.
  $to = $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(), $values, $from);

  // If the user requests it, send a copy using the current language.
  if ($values['copy']) {
    drupal_mail('contact', 'page_copy', $from, $language, $values, $from);
  }

  // Send an auto-reply if necessary using the current language.
  if ($values['category']['reply']) {
    drupal_mail('contact', 'page_autoreply', $from, $language, $values, $to);
  }
  flood_register_event('contact');
  watchdog('mail', '%sender-name (@sender-from) sent an e-mail regarding %category.', array(
    '%sender-name' => $values['name'],
    '@sender-from' => $from,
    '%category' => $values['category']['category'],
  ));

  // 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'] = '';
}