You are here

protected function SystemSendEmail::doExecute in Rules 8.3

Send a system email.

Parameters

string[] $to: Email addresses of the recipients.

string $subject: Subject of the email.

string $message: Email message text.

string|null $reply: (optional) Reply to email address.

\Drupal\Core\Language\LanguageInterface|null $language: (optional) Language code.

File

src/Plugin/RulesAction/SystemSendEmail.php, line 112

Class

SystemSendEmail
Provides "Send email" rules action.

Namespace

Drupal\rules\Plugin\RulesAction

Code

protected function doExecute(array $to, $subject, $message, $reply = NULL, LanguageInterface $language = NULL) {
  $langcode = isset($language) ? $language
    ->getId() : LanguageInterface::LANGCODE_SITE_DEFAULT;
  $params = [
    'subject' => $subject,
    'message' => $message,
  ];

  // Set a unique key for this email.
  $key = 'rules_action_mail_' . $this
    ->getPluginId();
  $recipients = implode(', ', $to);
  $message = $this->mailManager
    ->mail('rules', $key, $recipients, $langcode, $params, $reply);
  if ($message['result']) {
    $this->logger
      ->notice('Successfully sent email to %recipient', [
      '%recipient' => $recipients,
    ]);
  }
}