function rules_action_mail

Action Implementation: Send mail.

Related topics

1 string reference to 'rules_action_mail'
rules_system_action_info in modules/system.rules.inc
Implements hook_rules_action_info() on behalf of the system module.

File

modules/system.eval.inc, line 92

Code

function rules_action_mail($to, $subject, $message, $from, $langcode, $settings, RulesState $state, RulesPlugin $element) {
    $to = str_replace(array(
        "\r",
        "\n",
    ), '', $to);
    $from = !empty($from) ? str_replace(array(
        "\r",
        "\n",
    ), '', $from) : NULL;
    $params = array(
        'subject' => $subject,
        'message' => $message,
        'langcode' => $langcode,
    );
    // Set a unique key for this mail.
    $name = isset($element->root()->name) ? $element->root()->name : 'unnamed';
    $key = 'rules_action_mail_' . $name . '_' . $element->elementId();
    $languages = language_list();
    $language = isset($languages[$langcode]) ? $languages[$langcode] : language_default();
    $message = drupal_mail('rules', $key, $to, $language, $params, $from);
    if ($message['result']) {
        watchdog('rules', 'Successfully sent email to %recipient', array(
            '%recipient' => $to,
        ));
    }
}