Same name and namespace in other branches
  1. 4.7.x modules/contact.module \contact_mail_user_submit()
  2. 5.x modules/contact/contact.module \contact_mail_user_submit()

Process the personal contact page form submission.

File

modules/contact/contact.pages.inc, line 207
User page callbacks for the contact module.

Code

function contact_mail_user_submit($form, &$form_state) {
  global $user, $language;
  $account = $form_state['values']['recipient'];

  // Send from the current user to the requested user.
  $to = $account->mail;
  $from = $user->mail;

  // Save both users and all form values for email composition.
  $values = $form_state['values'];
  $values['account'] = $account;
  $values['user'] = $user;

  // Send the e-mail in the requested user language.
  drupal_mail('contact', 'user_mail', $to, user_preferred_language($account), $values, $from);

  // Send a copy if requested, using current page language.
  if ($form_state['values']['copy']) {
    drupal_mail('contact', 'user_copy', $from, $language, $values, $from);
  }
  flood_register_event('contact');
  watchdog('mail', '%name-from sent %name-to an e-mail.', array(
    '%name-from' => $user->name,
    '%name-to' => $account->name,
  ));
  drupal_set_message(t('The message has been sent.'));

  // Back to the requested users profile page.
  $form_state['redirect'] = "user/{$account->uid}";
}