Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Mailparse Functions : mailparse_rfc822_parse_addresses

mailparse_rfc822_parse_addresses

Parse RFC 822 compliant addresses (PHP 4 >= 4.0.7, PECL mailparse:0.9-2.1.1)
array mailparse_rfc822_parse_addresses ( string addresses )

Example 1134. mailparse_rfc822_parse_addresses() example

<?php

$to
= 'Wez Furlong <wez@example.com>, doe@example.com';
var_dump(mailparse_rfc822_parse_addresses($to));

?>

The above example will output:

array(2) {
 [0]=>
 array(3) {
   ["display"]=>
   string(11) "Wez Furlong"
   ["address"]=>
   string(15) "wez@example.com"
   ["is_group"]=>
   bool(false)
 }
 [1]=>
 array(3) {
   ["display"]=>
   string(15) "doe@example.com"
   ["address"]=>
   string(15) "doe@example.com"
   ["is_group"]=>
   bool(false)
 }
}

Code Examples / Notes » mailparse_rfc822_parse_addresses

dancablam

To just extract the email address out of an RFC822 line, it's faster and more reliable to just use a simple regex such as:
<?php
$rfc = '"Bob Smith" <bob@smith.com>';
preg_match('/[\\w\\.\\-+=*_]*@[\\w\\.\\-+=*_]*/', $rfc , $regs);
$parsed = $regs[0];
?>
The above code will pull out: bob@smith.com
No matter the variation of the RFC822 line, as long as there's a valid email address in it somewhere, the above regex will find it.


mat

If for some reason you cannot compile mailparse into your install of PHP, you will also find an extremely similar function in the Mail_MIME PEAR class, specifically in mimeDecode.php.

24-nov-2004 12:12

An alternative to the mailparse_rfc822_parse_addresses() function is Mail_RFC822::parseAddressList() from Pear:
http://pear.php.net/manual/en/package.mail.mail.php
It parses the string and returns a structured tree of data. Returns a pear_error object if the string is not valid.
Example:
require_once "PEAR.php";
require_once "Mail/RFC822.php";
                                                                               
$addr= "Hi <hi@world.org>";
                                                                               
$res= Mail_RFC822::parseAddressList($addr);
if (PEAR::isError($res)) die("NOT VALID: " . $res->getMessage() . "\n");
echo "OK. Data:\n";
print_r($res);


Change Language


Follow Navioo On Twitter
mailparse_determine_best_xfer_encoding
mailparse_msg_create
mailparse_msg_extract_part_file
mailparse_msg_extract_part
mailparse_msg_extract_whole_part_file
mailparse_msg_free
mailparse_msg_get_part_data
mailparse_msg_get_part
mailparse_msg_get_structure
mailparse_msg_parse_file
mailparse_msg_parse
mailparse_rfc822_parse_addresses
mailparse_stream_encode
mailparse_uudecode_all
eXTReMe Tracker