You are here

function views_contact_form_contact_form_submit in Views Contact Form 7

Form submission handler for views_contact_form_contact_form().

See also

views_contact_form_contact_form_validate()

File

./views_contact_form.form.inc, line 88

Code

function views_contact_form_contact_form_submit($form, &$form_state) {
  global $user, $language;
  $values = $form_state['values'];
  $values['sender'] = $user;
  $values['sender']->name = $values['name'];
  $values['sender']->mail = $values['mail'];
  $emails = $values['to'];

  // Save the anonymous user information to a cookie for reuse.
  if (!$user->uid) {
    user_cookie_save(array_intersect_key($values, array_flip(array(
      'name',
      'mail',
    ))));
  }

  // Get the to and from e-mail addresses.
  $from = $values['sender']->mail;
  foreach ($emails['emails'] as $email) {
    drupal_mail('views_contact_form', 'views_contact_form_page_mail', $email, language_default(), $values, $from);
    if ($values['copy']) {
      drupal_mail('views_contact_form', 'views_contact_form_page_copy', $from, $language, $values, $from);
    }
    watchdog('mail', '%sender-name (@sender-from) sent an e-mail.', array(
      '%sender-name' => $values['name'],
      '@sender-from' => $from,
    ));
  }
  flood_register_event('views_contact_form', variable_get('contact_threshold_window', 3600));
  drupal_set_message(t('Your message has been sent.'));
}