You are here

function webform_format_email_address in Webform 6.3

Same name and namespace in other branches
  1. 7.4 webform.module \webform_format_email_address()
  2. 7.3 webform.module \webform_format_email_address()

Given an email address and a name, format an e-mail address.

Parameters

$address: The e-mail address.

$name: The name to be used in the formatted address.

$node: The webform node if replacements will be done.

$submission: The webform submission values if replacements will be done.

$encode: Encode the text for use in an e-mail.

$single: Force a single value to be returned, even if a component expands to multiple addresses. This is useful to ensure a single e-mail will be returned for the "From" address.

$format: The e-mail format, defaults to the site-wide setting. May be either "short" or "long".

3 calls to webform_format_email_address()
webform_emails_form in includes/webform.emails.inc
Overview form of all components for this webform.
webform_submission_resend in includes/webform.submissions.inc
Form to resend specific e-mails associated with a submission.
webform_submission_send_mail in includes/webform.submissions.inc
Send related e-mails related to a submission.

File

./webform.module, line 3154

Code

function webform_format_email_address($address, $name, $node = NULL, $submission = NULL, $encode = TRUE, $single = TRUE, $format = NULL) {
  if (!isset($format)) {
    $format = variable_get('webform_email_address_format', 'long');
  }
  if ($name == 'default') {
    $name = webform_variable_get('webform_default_from_name');
  }
  elseif (is_numeric($name) && isset($node->webform['components'][$name])) {
    if (isset($submission->data[$name]['value'])) {
      $name = $submission->data[$name]['value'];
    }
    else {
      $name = t('Value of !component', array(
        '!component' => $node->webform['components'][$name]['name'],
      ));
    }
  }
  if ($address == 'default') {
    $address = webform_variable_get('webform_default_from_address');
  }
  elseif (is_numeric($address) && isset($node->webform['components'][$address])) {
    if (isset($submission->data[$address]['value'])) {
      $values = $submission->data[$address]['value'];
      $address = array();
      foreach ($values as $value) {
        $address = array_merge($address, explode(',', $value));
      }
    }
    else {
      $address = t('Value of "!component"', array(
        '!component' => $node->webform['components'][$address]['name'],
      ));
    }
  }

  // Convert arrays into a single value for From values.
  if ($single) {
    $address = is_array($address) ? reset($address) : $address;
    $name = is_array($name) ? reset($name) : $name;
  }

  // Address may be an array if a component value was used on checkboxes.
  if (is_array($address)) {
    foreach ($address as $key => $individual_address) {
      $address[$key] = _webform_filter_values($individual_address, $node, $submission, NULL, FALSE, TRUE);
    }
  }
  else {
    $address = _webform_filter_values($address, $node, $submission, NULL, FALSE, TRUE);
  }
  if ($format == 'long' && !empty($name)) {
    $name = _webform_filter_values($name, $node, $submission, NULL, FALSE, TRUE);
    if ($encode) {
      $name = mime_header_encode($name);
    }
    $name = trim($name);
    return '"' . $name . '" <' . $address . '>';
  }
  else {
    return $address;
  }
}