function SystemSendEmail::doExecute

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 113

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) {
    // ORIG.
    $langcode = isset($language) ? $language->getId() : LanguageInterface::LANGCODE_SITE_DEFAULT;
    // @todo Is this better?
    $langcode = isset($language) && $language->getId() != LanguageInterface::LANGCODE_NOT_SPECIFIED ? $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,
        ]);
    }
}