function contact_attach_contact_mail_user_submit in Contact Attach 5
Same name and namespace in other branches
- 6 contact_attach.module \contact_attach_contact_mail_user_submit()
Override contact_mail_user_submit().
Parameters
form_id: A unique string identifying the form.
form_values: The contents of the form fields.
Return value
The profile page to go to.
File
- ./
contact_attach.module, line 175 - 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_user_submit($form_id, $form_values) {
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[] = $form_values['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') . '] ' . $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:
drupal_mail('contact-user-mail', $to, $subject, $body, $from, $headers);
// Send a copy if requested:
if ($form_values['copy']) {
drupal_mail('contact-user-copy', $from, $subject, $body, $from, $headers);
}
// Log the operation:
flood_register_event('contact');
watchdog('mail', t('%name-from sent %name-to an e-mail.', array(
'%name-from' => $user->name,
'%name-to' => $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}";
}