You are here

function commerce_email_account_email_send in Commerce Email 7

1 string reference to 'commerce_email_account_email_send'
commerce_email_rules_action_info in ./commerce_email.rules.inc
Implements hook_rules_action_info().

File

./commerce_email.rules.inc, line 133
Defines rules for order email functionality.

Code

function commerce_email_account_email_send($account) {
  global $language;
  $site_email = variable_get('site_mail', '');
  $commerce_email_template = variable_get('commerce_email_account_template_' . $language->language, 0);
  $variables = array(
    'user' => $account,
  );

  // Load email content
  list($subject, $content) = commerce_email_load('account');
  $message = array(
    'id' => 'commerce_email_account',
    'module' => 'commerce_email',
    'key' => 'email_account',
    'to' => $account->mail,
    'from' => $site_email,
    'subject' => token_replace($subject, $variables, array(
      'language' => $language,
      'callback' => 'user_mail_tokens',
      'sanitize' => FALSE,
    )),
    'body' => array(
      '',
    ),
    'headers' => array(
      'Content-Type' => 'text/html; charset=UTF-8; format=flowed',
      'From' => $site_email,
      'Sender' => $site_email,
      'Return-Path' => $site_email,
    ),
  );
  if ($commerce_email_template == 1) {
    global $base_url;
    $login = user_pass_reset_url($variables['user']);
    $site = array(
      'site_name' => variable_get('site_name', "Commerce Email (default)"),
      'site_url' => $base_url,
    );
    $message['body'] = theme('commerce_account_email', array(
      'site' => $site,
      'user' => $variables['user'],
      'login' => $login,
      'language' => $language->language,
    ));
  }
  else {
    $message['body'] = token_replace($content, $variables, array(
      'language' => $language,
      'callback' => 'user_mail_tokens',
      'sanitize' => FALSE,
    ));
  }

  // Send user an account email
  commerce_email_mailsystem_send('account', $message);
}