You are here

function webform_parse_email_address in Webform 7.4

Parses an e-mail address into name and address.

Parameters

string $email: The email address to be parsed, with an optional name.

string $format: 'short', 'long', or NULL (for default) format. Long format has a name and the address in angle brackets.

Return value

array Associative array indexed by 'name' and 'address'.

3 calls to webform_parse_email_address()
webform_format_email_address in ./webform.module
Given an email address and a name, format an e-mail address.
webform_valid_email_address in ./webform.module
Validates email address(es) with optional name(s).
_webform_submission_prepare_mail in includes/webform.submissions.inc
Prepare a submission email for use by webform_submission_send_mail()

File

./webform.module, line 4763
This module provides a simple way to create forms and questionnaires.

Code

function webform_parse_email_address($email, $format = NULL) {
  if (!$format) {
    $format = webform_variable_get('webform_email_address_format');
  }
  if ($format == 'long') {

    // Match e-mails of the form 'My Name <email@domain.com>'.
    preg_match('/^"?([^<]*?)"? *(?:<(.*)>)?$/', $email, $matches);
    if (isset($matches[2]) && strlen($matches[2])) {
      return array(
        'name' => $matches[1],
        'address' => $matches[2],
      );
    }
  }
  return array(
    'name' => '',
    'address' => $email,
  );
}