protected function SendUserEmail::doExecute in Ubercart 8.4
Sends an email concerning an order.
The 'Sender', 'Recipients', 'Subject', and 'Message' fields accept order token replacements.
Parameters
\Drupal\uc_order\OrderInterface $order: The order object.
string $from: Sender's e-mail address.
string[] $addresses: Recipients' e-mail addresses.
string $subject: E-mail subject.
string $message: E-mail body.
string $format: Format filter machine name.
File
- uc_role/
src/ Plugin/ RulesAction/ SendUserEmail.php, line 65
Class
- SendUserEmail
- Provides a 'Send user email' action.
Namespace
Drupal\uc_role\Plugin\RulesActionCode
protected function doExecute(OrderInterface $order, $from, array $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,
];
// Apply token replacements to the 'from' e-mail address.
$from = $this->token
->replace($settings['from'], $settings['replacements']);
if (empty($from)) {
$from = uc_store_email_from();
}
// Split up our recipient e-mail addresses so we can send a
// separate e-mail to each.
$recipients = [];
foreach ($addresses as $address) {
$address = trim($address);
// Remove blank lines.
if (!empty($address)) {
// Apply token replacements to the 'recipient' e-mail address.
$recipients[] = $this->token
->replace($address, $settings['replacements']);
}
}
// Use uc_order's hook_mail() to send a separate e-mail to each recipient.
foreach ($recipients as $to) {
$sent = $this->mailManager
->mail('uc_order', 'rules-action-email', $to, uc_store_mail_recipient_langcode($to), $settings, $from);
if (!$sent['result']) {
$this->logger
->get('uc_role')
->error('Attempt to e-mail @email concerning order @order_id failed.', [
'@email' => $to,
'@order_id' => $order
->id(),
]);
}
}
}