function uc_file_action_order_email in Ubercart 8.4
Same name and namespace in other branches
- 6.2 uc_file/uc_file.ca.inc \uc_file_action_order_email()
- 7.3 uc_file/uc_file.rules.inc \uc_file_action_order_email()
Send an email with order and file replacement tokens.
The recipients, subject, and message fields take order token replacements.
1 string reference to 'uc_file_action_order_email'
- uc_file_rules_action_info in uc_file/
uc_file.rules.inc - Implements hook_rules_action_info().
File
- uc_file/
uc_file.rules.inc, line 227 - Rules hooks and functions for uc_file.module.
Code
function uc_file_action_order_email($order, $file_expiration, $from, $addresses, $subject, $message, $format) {
$settings = [
'from' => $from,
'addresses' => $addresses,
'subject' => $subject,
'message' => $message,
'format' => $format,
];
// Token replacements for the subject and body.
$settings['replacements'] = [
'uc_order' => $order,
'uc_file' => $file_expiration,
];
// Replace tokens and parse recipients.
$recipients = [];
$addresses = \Drupal::token()
->replace($settings['addresses'], $settings['replacements']);
foreach (explode("\n", $addresses) as $address) {
$recipients[] = trim($address);
}
// Send to each recipient.
foreach ($recipients as $email) {
$sent = \Drupal::service('plugin.manager.mail')
->mail('uc_order', 'action-mail', $email, uc_store_mail_recipient_langcode($email), $settings, $settings['from']);
if (!$sent['result']) {
\Drupal::logger('uc_file')
->error('Attempt to e-mail @email concerning order @order_id failed.', [
'@email' => $email,
'@order_id' => $order
->id(),
]);
}
}
}