Mail_RFC822::parseAddressList()

Mail_RFC822::parseAddressList() – extract the parts of a list of email addresses

Synopsis

require_once 'Mail/RFC822.php';

array parseAddressList ( string $address = '' , string $defaultDomain = 'localhost' , boolean $nestGroups = null , boolean $validate = null )

Description

Extracts the given addresses into their parts.

Parameter

  • string $address - the address(es) to validate

  • string $defaultDomain - the default domain to use in case of absence in the given email address.

  • boolean $nestGroups - whether to return the structure with groups nested for easier viewing.

  • boolean $validate - whether to validate atoms. Turn this off if you need to run addresses through before encoding the personal names, for instance.

Return value

array - a nested array of anonymous objects.

If $nestGroups set to FALSE, you can jump over the next paragraph.

Every array entry contains an object per group. This object has two attributes:

  • groupname - the name of the group
  • addresses - an array of all addresses of a group

The addresses array consists of an array of anonymous objects for each address. This object comes with the following attributes:

  • personal - the name of the address owner
  • comment - an array, an entry for each comment per address
  • mailbox - the name of the mailbox, the part before the @
  • host - the name of the server, the part after the @

Throws

Possible PEAR_Error values
Error code Error message Reason Solution
NULL every The given address string is not RFC822 compliant The error code contains a description of the error.

Note

This function can be called statically.

This class checks the string only. It does not check for the existence of an email address.

Example

Extract some addresses

<?php
$address 
'My group: "Richard" <richard@localhost>;, ted@example.com (A comment)';

$addresses Mail_RFC822::parseAddressList($address'phpguru.org'TRUE);
print_r($addresses);
?>
email address validation (Previous) Mail_IMAP (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.