You are here

function webform_submission_send_mail in Webform 7.4

Same name and namespace in other branches
  1. 6.3 includes/webform.submissions.inc \webform_submission_send_mail()
  2. 7.3 includes/webform.submissions.inc \webform_submission_send_mail()

Send related e-mails related to a submission.

This function is usually invoked when a submission is completed, but may be called any time e-mails should be redelivered.

Parameters

$node: The node object containing the current webform.

$submission: The webform submission object to be used in sending e-mails.

$emails: (optional) An array of specific e-mail settings to be used. If omitted, all e-mails in $node->webform['emails'] will be sent.

bool $send_disabled: (optional) When TRUE, send all emails, even those that are disabled.

Return value

int Number of mail sent.

2 calls to webform_submission_send_mail()
webform_client_form_submit in ./webform.module
Submit handler for saving the form values and sending e-mails.
webform_submission_resend_submit in includes/webform.submissions.inc
Submit handler for webform_submission_resend().

File

includes/webform.submissions.inc, line 242
Submission handling functions.

Code

function webform_submission_send_mail($node, $submission, $emails = NULL, $send_disabled = FALSE) {

  // Get the list of e-mails we'll be sending.
  $emails = isset($emails) ? $emails : $node->webform['emails'];

  // Create a themed message for mailing.
  $send_count = 0;
  foreach ($emails as $eid => $email) {
    if (!$send_disabled && !$email['status']) {
      continue;
    }
    $mail = _webform_submission_prepare_mail($node, $submission, $email);
    if (!$mail) {
      continue;
    }
    $addresses_final = $mail['addresses_final'];
    $send_increment = $mail['send_increment'];
    $language = $mail['language'];
    $mail_params = $mail['mail_params'];

    // Mail the webform results.
    foreach ($addresses_final as $address) {
      $message = drupal_mail('webform', 'submission', $address, $language, $mail_params, $email['from']);
      if ($message['result']) {
        $send_count += $send_increment;
      }
    }
  }
  return $send_count;
}