You are here

function contact_attach_contact_mail_page_submit in Contact Attach 6

Same name and namespace in other branches
  1. 5 contact_attach.module \contact_attach_contact_mail_page_submit()

Override contact_mail_page_submit().

Parameters

form: An associative array containing the structure of the form.

form_state: A keyed array containing the current state of the form.

1 string reference to 'contact_attach_contact_mail_page_submit'
contact_attach_form_alter in ./contact_attach.module
Implementation of hook_form_alter().

File

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

Code

function contact_attach_contact_mail_page_submit($form, &$form_state) {
  global $language;
  $values = $form_state['values'];

  // E-mail address of the sender: as the form field is a text field,
  // all instances of \r and \n have been automatically stripped from it.
  $from = $values['mail'];

  // Load category properties and save form values for email composition.
  $contact = contact_load($values['cid']);
  $values['contact'] = $contact;

  // Send the e-mail to the recipients using the site default language.
  $results[0] = drupal_mail('contact_attach', 'contact_page_mail', $contact['recipients'], language_default(), $values, $from);

  // If the user requests it, send a copy using the current language.
  if ($values['copy']) {
    $results[1] = drupal_mail('contact_attach', 'contact_page_copy', $from, $language, $values, $from);
  }

  // Send an auto-reply if necessary using the current language.
  if ($contact['reply']) {
    $results[2] = drupal_mail('contact_attach', 'contact_page_autoreply', $from, $language, $values, $contact['recipients']);
  }
  for ($i = 0; $i < 3; $i++) {
    if (!empty($results[$i])) {
      if (!$results[$i]['result']) {
        watchdog('mail', '%name-from attempted to send an e-mail regarding %category, but was unsuccessful.', array(
          '%name-from' => $values['name'] . " [{$from}]",
          '%category' => $contact['category'],
        ));
        drupal_set_message(t('Your message was NOT sent.'));
      }
      else {
        flood_register_event('contact');
        watchdog('mail', '%name-from sent an e-mail regarding %category.', array(
          '%name-from' => $values['name'] . " [{$from}]",
          '%category' => $contact['category'],
        ));
        drupal_set_message(t('Your message has been sent.'));
      }
    }
  }

  // Jump to home page rather than back to contact page to avoid
  // contradictory messages if flood control has been activated.
  $form_state['redirect'] = '';
}