contact.module 23.3 KB
Newer Older
Dries's avatar
   
Dries committed
1
2
3
4
5
<?php
// $Id$

/**
 * @file
6
 * Enables the use of personal and site-wide contact forms.
Dries's avatar
   
Dries committed
7
8
9
10
11
12
13
 */

/**
 * Implementation of hook_help().
 */
function contact_help($section) {
  switch ($section) {
14
    case 'admin/help#contact':
15
16
      $output = '<p>'. t('The contact module enables the use of both personal and site-wide contact forms, thereby facilitating easy communication within the community. While personal contact forms allow users to contact each other by e-mail, site-wide forms allow community members to contact the site administration from a central location. Users can specify a subject and message in the contact form, and also request that a copy of the e-mail be sent to their own address.') .'</p>';
      $output .= '<p>'. t("Users can activate/deactivate their personal contact forms in their account settings. Upon activation, a contact tab will appear in their user profiles. Privileged users such as site administrators are able to contact users even if they have chosen not to enable this feature.") .'</p>';
17
      $output .= '<p>'. t("Note that the contact tab will not appear when a user views his or her own profile; only when viewing another user's profile, if that user's contact form is enabled.") .'</p>';
18
      $output .= '<p>'. t('If the menu module is enabled, a menu item linking to the site-wide contact page is added to the navigation block. It is disabled by default, but can be enabled via the <a href="%menu-module">menu management</a> page. Links to the contact page may also be added to the primary and secondary links using the same page.', array('%menu-module' => url('admin/build/menu'))) .'</p>';
19
20
      $output .= t('Contact module links:') .'<ul>';
      $output .= '<li>'. t('Default site-wide <a href="%contact-page">contact page</a>.', array('%contact-page' => url('contact'))) .'</li>';
21
22
23
      $output .= '<li>'. t('Site-wide contact form <a href="%configuration-page">category configuration</a>.', array('%configuration-page' => url('admin/build/contact'))) .'</li>';
      $output .= '<li>'. t('Site-wide contact form <a href="%additional-settings">general settings</a>.', array('%additional-settings' => url('admin/build/contact/settings'))) .'</li>';
      $output .= '<li>'. t('Site-wide contact form <a href="%menu-configuration">menu configuration</a>.', array('%menu-configuration' => url('admin/build/menu'))) .'</li></ul>';
24
      $output .= t('For more information, please read the configuration and customization handbook page for the <a href="%contact">contact module</a>.', array('%contact' => url('http://drupal.org/handbook/modules/contact/', NULL, NULL, TRUE)));
25
      return $output;
26
    case 'admin/settings/modules#description':
27
      return t('Enables the use of both personal and site-wide contact forms.');
28
29
    case 'admin/build/contact':
      $output = t('This page lets you setup <a href="%form">your site-wide contact form</a>. To do so, add one or more categories. You can associate different recipients with each category to route e-mails to different people. For example, you can route website feedback to the webmaster and direct product information requests to the sales department. On the <a href="%settings">settings page</a>, you can customize the information shown above the contact form. This can be useful to provide additional contact information such as your postal address and telephone number.', array('%settings' => url('admin/build/contact/settings'), '%form' => url('contact')));
30
      if (!module_exist('menu')) {
31
        $menu_note = t('The menu item can be customized and configured only once the menu module has been <a href="%modules-page">enabled</a>.', array('%modules-page' => url('admin/settings/modules')));
32
33
34
35
      }
      else {
        $menu_note = '';
      }
36
      $output .= '<p>'. t('The contact module also adds a <a href="%menu-settings">menu item</a> (disabled by default) to the navigation block.', array('%menu-settings' => url('admin/build/menu'))) .' '. $menu_note .'</p>';
37
      return($output);
Dries's avatar
   
Dries committed
38
39
40
  }
}

41
42
43
44
45
46
/**
 * Implementation of hook_perm
 */
function contact_perm() {
  return array('access site-wide contact form', 'access personal contact forms');
}
Dries's avatar
   
Dries committed
47
48
49
50
/**
 * Implementation of hook_menu().
 */
function contact_menu($may_cache) {
51
  $items = array();
52
  if ($may_cache) {
53
    $items[] = array('path' => 'admin/build/contact',
54
      'title' => t('contact form'),
55
      'description' => t('Create a system contact form and set up categories for the form to use.'),
56
57
58
      'callback' => 'contact_admin_categories',
      'access' => user_access('administer site configuration'),
    );
59
    $items[] = array('path' => 'admin/build/contact/list',
60
61
62
63
64
      'title' => t('list'),
      'callback' => 'contact_admin_categories',
      'access' => user_access('administer site configuration'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
    );
65
    $items[] = array('path' => 'admin/build/contact/add',
66
67
68
69
70
71
      'title' => t('add category'),
      'callback' => 'contact_admin_edit',
      'access' => user_access('administer site configuration'),
      'type' => MENU_LOCAL_TASK,
      'weight' => 1,
    );
72
    $items[] = array('path' => 'admin/build/contact/edit',
73
74
75
76
77
      'title' => t('edit contact category'),
      'callback' => 'contact_admin_edit',
      'access' => user_access('administer site configuration'),
      'type' => MENU_CALLBACK,
    );
78
    $items[] = array('path' => 'admin/build/contact/delete',
79
80
81
82
83
      'title' => t('delete contact'),
      'callback' => 'contact_admin_delete',
      'access' => user_access('administer site configuration'),
      'type' => MENU_CALLBACK,
    );
84
85
    $items[] = array('path' => 'admin/build/contact/settings',
      'title' => t('settings'),
86
87
      'callback' => 'contact_admin_settings',
      'access' => user_access('administer site configuration'),
88
89
      'type' => MENU_LOCAL_TASK,
      'weight' => 2,
90
91
92
93
    );
    $items[] = array('path' => 'contact',
      'title' => t('contact'),
      'callback' => 'contact_mail_page',
94
      'access' => user_access('access site-wide contact form'),
95
96
      'type' => MENU_SUGGESTED_ITEM,
    );
97
98
  }
  else {
Dries's avatar
   
Dries committed
99
    if (arg(0) == 'user' && is_numeric(arg(1))) {
100
      global $user;
101
      $account = user_load(array('uid' => arg(1)));
102
      if (($user->uid != $account->uid && $account->contact) || user_access('administer users')) {
103
104
105
106
107
108
109
110
111
        global $user;
        $items[] = array('path' => 'user/'. arg(1) .'/contact',
          'title' => t('contact'),
          'callback' => 'contact_mail_user',
          'type' => MENU_LOCAL_TASK,
          'access' => ($user->uid && user_access('access personal contact forms')),
          'weight' => 2,
        );
      }
Dries's avatar
   
Dries committed
112
113
114
115
116
117
118
119
120
    }
  }

  return $items;
}

/**
 * Implementation of hook_user().
 *
121
 * Allows the user the option of enabling/disabling his personal contact form.
Dries's avatar
   
Dries committed
122
 */
123
function contact_user($type, &$edit, &$user, $category = NULL) {
Dries's avatar
   
Dries committed
124
  if ($type == 'form' && $category == 'account') {
125
126
127
128
129
130
131
132
    $form['contact'] = array('#type' => 'fieldset',
      '#title' => t('Contact settings'),
      '#weight' => 5,
      '#collapsible' => TRUE,
    );
    $form['contact']['contact'] = array('#type' => 'checkbox',
      '#title' => t('Personal contact form'),
      '#default_value' => $edit['contact'],
133
      '#description' => t('Allow other users to contact you by e-mail via <a href="%url">your personal contact form</a>. Note that while your e-mail address is not made public to other members of the community, privileged users such as site administrators are able to contact you even if you choose not to enable this feature.', array('%url' => url("user/$user->uid/contact"))),
134
    );
135
    return $form;
Dries's avatar
   
Dries committed
136
  }
137
  elseif ($type == 'validate') {
Dries's avatar
   
Dries committed
138
139
    return array('contact' => $edit['contact']);
  }
140
141
142
  elseif ($type == 'insert') {
    $edit['contact'] = variable_get('contact_default_status', 1);
  }
Dries's avatar
   
Dries committed
143
144
}

145
146
147
148
149
150
151
/**
 * Categories/list tab.
 */
function contact_admin_categories() {
  $result = db_query('SELECT cid, category, recipients, selected FROM {contact} ORDER BY weight, category');
  $rows = array();
  while ($category = db_fetch_object($result)) {
152
    $rows[] = array($category->category, $category->recipients, ($category->selected ? t('Yes') : t('No')), l(t('edit'), 'admin/build/contact/edit/'. $category->cid), l(t('delete'), 'admin/build/contact/delete/'. $category->cid));
153
154
155
156
157
158
159
160
161
162
  }
  $header = array(t('Category'), t('Recipients'), t('Selected'), array('data' => t('Operations'), 'colspan' => 2));

  return theme('table', $header, $rows);
}

/**
 * Category edit page.
 */
function contact_admin_edit($cid = NULL) {
163
  if (arg(3) == "edit" && $cid > 0) {
164
    $edit = db_fetch_array(db_query("SELECT * FROM {contact} WHERE cid = %d", $cid));
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
  }
  $form['category'] = array('#type' => 'textfield',
    '#title' => t('Category'),
    '#maxlength' => 255,
    '#default_value' => $edit['category'],
    '#description' => t("Example: 'website feedback' or 'product information'."),
    '#required' => TRUE,
  );
  $form['recipients'] = array('#type' => 'textarea',
    '#title' => t('Recipients'),
    '#default_value' => $edit['recipients'],
    '#description' => t("Example: 'webmaster@yoursite.com' or 'sales@yoursite.com'. To specify multiple recipients, separate each e-mail address with a comma."),
    '#required' => TRUE,
  );
  $form['reply'] = array('#type' => 'textarea',
    '#title' => t('Auto-reply'),
    '#default_value' => $edit['reply'],
    '#description' => t('Optional auto-reply. Leave empty if you do not want to send the user an auto-reply message.'),
  );
  $form['weight'] = array('#type' => 'weight',
    '#title' => t('Weight'),
    '#default_value' => $edit['weight'],
    '#description' => t('When listing categories, those with lighter (smaller) weights get listed before categories with heavier (larger) weights. Categories with equal weights are sorted alphabetically.'),
  );
  $form['selected'] = array('#type' => 'select',
    '#title' => t('Selected'),
    '#options' => array('0' => t('No'), '1' => t('Yes')),
    '#default_value' => $edit['selected'],
    '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
  );
195
  $form['cid'] = array('#type' => 'value',
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
    '#value' => $edit['cid'],
  );
  $form['submit'] = array('#type' => 'submit',
    '#value' => t('Submit'),
  );

  return drupal_get_form('contact_admin_edit', $form);
}

/**
 * Validate the contact category edit page form submission.
 */
function contact_admin_edit_validate($form_id, $form_values) {
  if (empty($form_values['category'])) {
    form_set_error('category', t('You must enter a category.'));
  }
  if (empty($form_values['recipients'])) {
    form_set_error('recipients', t('You must enter one or more recipients.'));
  }
  else {
    $recipients = explode(',', $form_values['recipients']);
    foreach($recipients as $recipient) {
      if (!valid_email_address(trim($recipient))) {
219
        form_set_error('recipients', t('%recipient is an invalid e-mail address.', array('%recipient' => theme('placeholder', $recipient))));
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
      }
    }
  }
}

/**
 * Process the contact category edit page form submission.
 */
function contact_admin_edit_submit($form_id, $form_values) {
  if ($form_values['selected']) {
    // Unselect all other contact categories.
    db_query('UPDATE {contact} SET selected = 0');
  }
  $recipients = explode(',', $form_values['recipients']);
  foreach($recipients as $key=>$recipient) {
    // E-mail address validation has already been done in _validate.
    $recipients[$key] = trim($recipient);
  }
  $form_values['recipients'] = implode(',', $recipients);
239
  if (arg(3) == 'add') {
240
241
    db_query("INSERT INTO {contact} (category, recipients, reply, weight, selected) VALUES ('%s', '%s', '%s', %d, %d)", $form_values['category'], $form_values['recipients'], $form_values['reply'], $form_values['weight'], $form_values['selected']);
    drupal_set_message(t('Category %category has been added.', array('%category' => theme('placeholder', $form_values['category']))));
242
    watchdog('mail', t('Contact form: category %category added.', array('%category' => theme('placeholder', $form_values['category']))), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
243
244
245
246
247

  }
  else {
    db_query("UPDATE {contact} SET category = '%s', recipients = '%s', reply = '%s', weight = %d, selected = %d WHERE cid = %d", $form_values['category'], $form_values['recipients'], $form_values['reply'], $form_values['weight'], $form_values['selected'], $form_values['cid']);
    drupal_set_message(t('Category %category has been updated.', array('%category' => theme('placeholder', $form_values['category']))));
248
    watchdog('mail', t('Contact form: category %category updated.', array('%category' => theme('placeholder', $form_values['category']))), WATCHDOG_NOTICE, l(t('view'), 'admin/build/contact'));
249
250
  }

251
  return 'admin/build/contact';
252
253
254
255
256
257
258
}

/**
 * Category delete page.
 */
function contact_admin_delete($cid = NULL) {
  if ($info = db_fetch_object(db_query("SELECT category FROM {contact} WHERE cid = %d", $cid))) {
259
    $form['category'] = array('#type' => 'value',
260
261
262
      '#value' => $info->category,
    );

263
    return confirm_form('contact_admin_delete', $form, t('Are you sure you want to delete %category?', array('%category' => theme('placeholder', $info->category))), 'admin/build/contact', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
264
265
266
  }
  else {
    drupal_set_message(t('Category not found.'), 'error');
267
    drupal_goto('admin/build/contact');
268
269
270
271
272
273
274
  }
}

/**
 * Process category delete form submission.
 */
function contact_admin_delete_submit($form_id, $form_values) {
275
  db_query("DELETE FROM {contact} WHERE cid = %d", arg(4));
276
277
278
  drupal_set_message(t('Category %category has been deleted.', array('%category' => theme('placeholder', $form_values['category']))));
  watchdog('mail', t('Contact form: category %category deleted.', array('%category' => theme('placeholder', $form_values['category']))), WATCHDOG_NOTICE);

279
  return 'admin/build/contact';
280
281
282
283
284
285
286
287
288
289
290
291
292
293
}

function contact_admin_settings() {
  $form['contact_form_information'] = array('#type' => 'textarea',
    '#title' => t('Additional information'),
    '#default_value' => variable_get('contact_form_information', t('You can leave a message using the contact form below.')),
    '#description' => t('Information to show on the <a href="%form">contact page</a>. Can be anything from submission guidelines to your postal address or telephone number.', array('%form' => url('contact'))),
  );
  $form['contact_hourly_threshold'] = array('#type' => 'select',
    '#title' => t('Hourly threshold'),
    '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50)),
    '#default_value' => variable_get('contact_hourly_threshold', 3),
    '#description' => t('The maximum number of contact form submissions a user can perform per hour.'),
  );
294
295
296
297
298
299
  $form['contact_default_status'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable personal contact form by default'),
    '#default_value' => variable_get('contact_default_status', 1),
    '#description' => t('Default status of the personal contact form for new users.'),
  );
300
301
302
303
304
305
  $form['submit'] = array('#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  $form['reset'] = array('#type' => 'submit',
    '#value' => t('Reset to defaults'),
  );
Dries's avatar
Dries committed
306

307
  return drupal_get_form('contact_admin_settings', $form, 'system_settings_form');
308
309
310
311
312
}

/**
 * Personal contact page.
 */
Dries's avatar
   
Dries committed
313
314
315
function contact_mail_user() {
  global $user;

316
  if ($account = user_load(array('uid' => arg(1)))) {
317
    if (!valid_email_address($user->mail)) {
318
      $output = t('You need to provide a valid e-mail address to contact other users. Please update your <a href="%url">user information</a> and try again.', array('%url' => url("user/$user->uid/edit")));
Dries's avatar
   
Dries committed
319
    }
320
    else if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
321
      $output = t('You cannot contact more than %number users per hour. Please try again later.', array('%number' => variable_get('contact_hourly_threshold', 3)));
Dries's avatar
   
Dries committed
322
323
    }
    else {
324
325
      drupal_set_title($account->name);

326
      $form['#token'] = $user->name . $user->mail;
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
      $form['from'] = array('#type' => 'item',
        '#title' => t('From'),
        '#value' => $user->name .' &lt;'. $user->mail .'&gt;',
      );
      $form['to'] = array('#type' => 'item',
        '#title' => t('To'),
        '#value' => $account->name,
      );
      $form['subject'] = array('#type' => 'textfield',
        '#title' => t('Subject'),
        '#maxlength' => 50,
        '#required' => TRUE,
      );
      $form['message'] = array('#type' => 'textarea',
        '#title' => t('Message'),
        '#rows' => 15,
        '#required' => TRUE,
      );
      $form['copy'] = array('#type' => 'checkbox',
346
        '#title' => t('Send yourself a copy.'),
347
348
      );
      $form['submit'] = array('#type' => 'submit',
349
        '#value' => t('Send e-mail'),
350
351
      );
      $output = drupal_get_form('contact_mail_user', $form);
Dries's avatar
   
Dries committed
352
353
    }

Dries's avatar
   
Dries committed
354
    return $output;
Dries's avatar
   
Dries committed
355
356
357
358
359
360
  }
  else {
    drupal_not_found();
  }
}

361
362
363
/**
 * Process the personal contact page form submission.
 */
364
function contact_mail_user_submit($form_id, $edit) {
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
  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:
391
  drupal_mail('contact-user-mail', $to, $subject, $body, $from);
392
393
394

  // Send a copy if requested:
  if ($edit['copy']) {
395
    drupal_mail('contact-user-copy', $from, $subject, $body, $from);
396
397
398
399
400
401
402
403
404
405
  }

  // 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:
406
  return "user/$account->uid";
407
408
}

409
410
411
/**
 * Site-wide contact page
 */
412
413
414
function contact_mail_page() {
  global $user;

415
  if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
416
    $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3)));
417
418
  }
  else {
419
    if ($user->uid) {
420
421
422
      $edit['name'] = $user->name;
      $edit['mail'] = $user->mail;
    }
423

424
    $result = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category');
Dries's avatar
Dries committed
425
    while ($category = db_fetch_object($result)) {
426
427
428
429
      $categories[$category->cid] = $category->category;
      if ($category->selected) {
        $default_category = $category->cid;
      }
430
431
    }

432
    if (count($categories) > 0) {
433
      $form['#token'] = $user->name . $user->mail;
434
      $form['contact_information'] = array('#value' => filter_xss_admin(variable_get('contact_form_information', t('You can leave us a message using the contact form below.'))));
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
      $form['name'] = array('#type' => 'textfield',
        '#title' => t('Your name'),
        '#maxlength' => 255,
        '#default_value' => $edit['name'],
        '#required' => TRUE,
      );
      $form['mail'] = array('#type' => 'textfield',
        '#title' => t('Your e-mail address'),
        '#maxlength' => 255,
        '#default_value' => $edit['mail'],
        '#required' => TRUE,
      );
      $form['subject'] = array('#type' => 'textfield',
        '#title' => t('Subject'),
        '#maxlength' => 255,
        '#required' => TRUE,
      );
452
453
454
455
456
457
      if (count($categories) > 1) {
        // If there is more than one category available and no default category has been selected,
        // prepend a default placeholder value.
        if (!isset($default_category)) {
          $categories = array(t('--')) + $categories;
        }
458
459
460
461
462
463
        $form['cid'] = array('#type' => 'select',
          '#title' => t('Category'),
          '#default_value' => $default_category,
          '#options' => $categories,
          '#required' => TRUE,
        );
Dries's avatar
Dries committed
464
      }
465
466
      else {
        // If there is only one category, store its cid.
467
        $category_keys = array_keys($categories);
468
        $form['cid'] = array('#type' => 'value',
469
          '#value' => array_shift($category_keys),
470
471
        );
      }
472
473
474
475
476
      $form['message'] = array('#type' => 'textarea',
        '#title' => t('Message'),
        '#required' => TRUE,
      );
      $form['copy'] = array('#type' => 'checkbox',
477
        '#title' => t('Send yourself a copy.'),
478
479
480
481
      );
      $form['submit'] = array('#type' => 'submit',
        '#value' => t('Send e-mail'),
      );
482
      $output = drupal_get_form('contact_mail_page', $form);
483
484
485
486
487
488
    }
    else {
      $output = t('The contact form has not been configured.');
    }
  }

Dries's avatar
   
Dries committed
489
  return $output;
490
}
491

492
493
494
/**
 * Validate the site-wide contact page form submission.
 */
495
496
497
498
499
500
function contact_mail_page_validate($form_id, $form_values) {
  if (!$form_values['cid']) {
    form_set_error('category', t('You must select a valid category.'));
  }
  if (!valid_email_address($form_values['mail'])) {
    form_set_error('mail', t('You must enter a valid e-mail address.'));
501
502
503
  }
}

504
505
506
/**
 * Process the site-wide contact page form submission.
 */
507
function contact_mail_page_submit($form_id, $edit) {
508

Dries's avatar
Dries committed
509
  // E-mail address of the sender: as the form field is a text field,
510
  // all instances of \r and \n have been automatically stripped from it.
511
512
513
  $from = $edit['mail'];

  // Compose the body:
Dries's avatar
Dries committed
514
  $message[] = t("%name sent a message using the contact form at %form.", array('%name' => $edit['name'], '%form' => url($_GET['q'], NULL, NULL, TRUE)));
515
516
517
518
519
520
521
  $message[] = $edit['message'];

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

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

525
  // Format the category:
526
  $subject = t('[%category] %subject', array('%category' => $contact->category, '%subject' => $edit['subject']));
527
528
529
530
531

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

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

  // If the user requests it, send a copy.
  if ($edit['copy']) {
536
    drupal_mail('contact-page-copy', $from, $subject, $body, $from);
537
538
539
540
  }

  // Send an auto-reply if necessary:
  if ($contact->reply) {
541
    drupal_mail('contact-page-autoreply', $from, $subject, wordwrap($contact->reply), $contact->recipients);
542
543
544
545
546
547
  }

  // 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))));

548
  // Update user:
549
550
  drupal_set_message(t('Your message has been sent.'));

551
552
  // Jump to home page rather than back to contact page to avoid contradictory messages if flood control has been activated.
  return('');
553
}