You are here

function contact_mail_user_submit in Drupal 4

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

Process the personal contact page form submission.

File

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

Code

function contact_mail_user_submit($form_id, $edit) {
  global $user;
  $account = user_load(array(
    'uid' => arg(1),
    'status' => 1,
  ));

  // Compose the body:
  $message[] = "{$account->name},";
  $message[] = t("%name (%name-url) has sent you a message via your contact form (%form-url) at %site.", array(
    '%name' => $user->name,
    '%name-url' => url("user/{$user->uid}", NULL, NULL, TRUE),
    '%form-url' => url($_GET['q'], NULL, NULL, TRUE),
    '%site' => variable_get('site_name', 'drupal'),
  ));
  $message[] = t("If you don't want to receive such e-mails, you can change your settings at %url.", array(
    '%url' => url("user/{$account->uid}", NULL, NULL, TRUE),
  ));
  $message[] = t('Message:');
  $message[] = $edit['message'];

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

  // Prepare all fields:
  $to = $account->mail;
  $from = $user->mail;

  // Format the subject:
  $subject = '[' . variable_get('site_name', 'drupal') . '] ' . $edit['subject'];

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

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

  // Send a copy if requested:
  if ($edit['copy']) {
    user_mail($from, $subject, $body, "From: {$from}\nReply-to: {$from}\nX-Mailer: Drupal\nReturn-path: {$from}\nErrors-to: {$from}");
  }

  // Log the operation:
  flood_register_event('contact');
  watchdog('mail', t('%name-from sent %name-to an e-mail.', array(
    '%name-from' => theme('placeholder', $user->name),
    '%name-to' => theme('placeholder', $account->name),
  )));

  // Set a status message:
  drupal_set_message(t('The message has been sent.'));

  // Jump to the user's profile page:
  return "user/{$account->uid}";
}