You are here

function contact_attach_contact_mail_page_submit in Contact Attach 5

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

Override contact_mail_page_submit().

Parameters

form_id: A unique string identifying the form.

form_values: The contents of the form fields.

Return value

An empty string.

File

./contact_attach.module, line 270
This is the main code file for the Contact attach module. This module gives users the ability of attaching one or more files to e-mails sent using the site-wide contact form.

Code

function contact_attach_contact_mail_page_submit($form_id, $form_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 = $form_values['mail'];

  // Compose the body:
  $message[] = t("!name sent a message using the contact form at !form.", array(
    '!name' => $form_values['name'],
    '!form' => url($_GET['q'], NULL, NULL, TRUE),
  ));
  $message[] = $form_values['message'];

  // Tidy up the body:
  foreach ($message as $key => $value) {
    $message[$key] = wordwrap($value);
  }

  // Load the category information:
  $contact = db_fetch_object(db_query("SELECT * FROM {contact} WHERE cid = %d", $form_values['cid']));

  // Format the category:
  $subject = t('[!category] !subject', array(
    '!category' => $contact->category,
    '!subject' => $form_values['subject'],
  ));

  // Attachment processing begins here.
  $return_message = _contact_attach_process_attachments($message);
  if (!empty($return_message)) {
    $headers = $return_message['headers'];
    $body = $return_message['body'];
  }
  else {
    $headers = array();

    // Prepare the body:
    $body = implode("\n\n", $message);
  }

  // Send the e-mail to the recipients:
  drupal_mail('contact-page-mail', $contact->recipients, $subject, $body, $from, $headers);

  // If the user requests it, send a copy.
  if ($form_values['copy']) {
    drupal_mail('contact-page-copy', $from, $subject, $body, $from, $headers);
  }

  // Send an auto-reply if necessary:
  if ($contact->reply) {
    drupal_mail('contact-page-autoreply', $from, $subject, wordwrap($contact->reply), $contact->recipients);
  }

  // Log the operation:
  flood_register_event('contact');
  watchdog('mail', t('%name-from sent an e-mail regarding %category.', array(
    '%name-from' => $form_values['name'] . " <{$from}>",
    '%category' => $contact->category,
  )));

  // Update user:
  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.
  return '';
}