You are here

function contact_mail_page_submit in Drupal 4

Same name and namespace in other branches
  1. 5 modules/contact/contact.module \contact_mail_page_submit()
  2. 6 modules/contact/contact.pages.inc \contact_mail_page_submit()

Process the site-wide contact page form submission.

File

modules/contact.module, line 504
Enables the use of personal and site-wide contact forms.

Code

function contact_mail_page_submit($form_id, $edit) {

  // 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 = $edit['mail'];

  // Compose the body:
  $message[] = t("%name sent a message using the contact form at %form.", array(
    '%name' => $edit['name'],
    '%form' => url($_GET['q'], NULL, NULL, TRUE),
  ));
  $message[] = $edit['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", $edit['cid']));

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

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

  // Send the e-mail to the recipients:
  user_mail($contact->recipients, $subject, $body, "From: {$from}\nReply-to: {$from}\nX-Mailer: Drupal\nReturn-path: {$from}\nErrors-to: {$from}");

  // If the user requests it, send a copy.
  if ($edit['copy']) {
    user_mail($from, $subject, $body, "From: {$from}\nReply-to: {$from}\nX-Mailer: Drupal\nReturn-path: {$from}\nErrors-to: {$from}");
  }

  // Send an auto-reply if necessary:
  if ($contact->reply) {
    user_mail($from, $subject, wordwrap($contact->reply), "From: {$contact->recipients}\nReply-to: {$contact->recipients}\nX-Mailer: Drupal\nReturn-path: {$contact->recipients}\nErrors-to: {$contact->recipients}");
  }

  // Log the operation:
  flood_register_event('contact');
  watchdog('mail', t('%name-from sent an e-mail regarding %category.', array(
    '%name-from' => theme('placeholder', $edit['name'] . " <{$from}>"),
    '%category' => theme('placeholder', $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 '';
}