You are here

function workbench_email_mail_send in Workbench Email 7.3

Same name and namespace in other branches
  1. 7 workbench_email.module \workbench_email_mail_send()

Determines the emails attributes.

Sets the emails subject / message and sends the email.

Parameters

string $email: The send to email address

object $email_transition: The email transition used for determining the subject / message to retrieve

object $node: The node returned from node_save

2 calls to workbench_email_mail_send()
workbench_email_notification_submit in ./workbench_email.form.inc
Submit handler for the workbench_email form element.
workbench_email_workbench_moderation_transition in ./workbench_email.module
Implements hook_workbench_moderation_transition().

File

./workbench_email.module, line 149
Code for the Workbench Email Module.

Code

function workbench_email_mail_send($email, $email_transition, $node) {
  $module = 'workbench_email';
  $key = 'we_transition';
  $to = $email;
  $from = variable_get('site_mail', 'admin@example.com');
  $role = workbench_email_get_role_by_rid($email_transition->rid);
  if (empty($email_transition->subject) && empty($email_transition->message)) {
    drupal_set_message(t('No workbench email template found, so no email was sent.
      Contact your system admin to resolve this issue.'), 'error', FALSE);
    watchdog('workbench_email', 'No workbench email template found, so no email was sent.
      Contact your system admin to resolve this issue.
      From State: !from_state
      New State: !new_state
      Role: !role_name', array(
      '!from_state' => $email_transition->from_name,
      '!new_state' => $email_transition->to_name,
      '!role_name' => $role->name,
    ));
    return;
  }
  global $user;
  $params['subject'] = $email_transition->subject;
  $params['message'] = $email_transition->message;
  $params['node'] = $node;
  $params['user'] = $user;
  $params['workbench_email']['account'] = user_load_by_mail($email);
  $params['workbench_email']['email_transition'] = $email_transition;
  $language = language_default();
  $send = TRUE;
  $result = drupal_mail($module, $key, $to, $language, $params, $from, $send);
  $queue_mail = variable_get('workbench_email_queue_mail');
  if (!$queue_mail) {
    if ($result['result'] == TRUE) {
      drupal_set_message(t('Email notifications sent.'), 'status', FALSE);
    }
    elseif ($result['result'] == NULL) {
      return;
    }
    else {
      drupal_set_message(t('There was a problem sending the
                         email notifications. No messages were
                         sent.'), 'error', FALSE);
      watchdog('workbench_email', 'There was a problem sending the email notifications.
        No messages were sent.
        From State: !from_state
        New State: !new_state
        Role: !role_name
        To: !to', array(
        '!from_state' => $email_transition->from_name,
        '!new_state' => $email_transition->to_name,
        '!role_name' => $role->name,
        '!to' => $to,
      ));
    }
  }
  else {
    drupal_set_message(t('Email notifications have been queued and will be sent shortly.'), 'status', FALSE);
  }
}