php-extended / php-email-address-object
A library that implements the php-extended/php-email-address-interface interface library.
Requires
Requires (Dev)
- dev-master
- 4.0.0
- 3.5.7
- 3.5.6
- 3.5.5
- 3.5.4
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.23
- 3.2.22
- 3.2.21
- 3.2.20
- 3.2.19
- 3.2.18
- 3.2.17
- 3.2.16
- 3.2.15
- 3.2.14
- 3.2.13
- 3.2.12
- 3.2.11
- 3.2.10
- 3.2.9
- 3.2.8
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
This package is auto-updated.
Last update: 2022-07-31 00:27:38 UTC
README
A library that implements the php-extended/php-email-address-interface library.
Installation
The installation of this library is made via composer.
Download composer.phar
from their website.
Then add to your composer.json :
"require": {
...
"php-extended/php-email-address-object": "^3"
...
}
Then run php composer.phar update
to install this library.
The autoloading of all classes of this library is made through composer's autoloader.
Basic Usage
To use this interface, you may do the following :
use PhpExtended\Email\EmailAddress;
use PhpExtended\Email\Mailbox;
use PhpExtended\Email\MailboxGroup;
use PhpExtended\Email\MailboxGroupList;
$email = new EmailAddress('example', 'example.com'); // example@example.com
$email->__toString(); // echo example@example.com
$mailbox = new Mailbox($email, 'Example, Inc');
$mailbox->__toString(); // echo "Example, Inc" <example@example.com>
$mailboxList = new MailboxList([$mailbox]);
$mailboxList->__toString(); // echo "Example, Inc" <example@example.com>
$mailboxGroup = new MailboxGroup($mailboxList, 'All Examples');
$mailboxGroup->__toString(); // echo "All Examples": "Example, Inc" <example@example.com>
$mailboxGroupList = new MailboxGroupList([$mailboxGroup]);
$mailboxGroupList = $mailboxGroupList->withEmailAddress(new EmailAddress('example2', 'example.com'), 'Example2, Inc', 'Other Examples');
$mailboxGroupList->__toString(); // echo "All Examples": "Example, Inc" <example@example.com>; "Other Examples": "Example2, Inc" <example2@example.com>
$emails = $mailboxGroupList->collectEmailAddresses();
echo implode(', ', iterator_to_array($emails)); // echo "example@example.com, example2@example.com"
To parse email addresses, you may do the following :
use PhpExtended\Email\EmailAddressParser;
$parser = new EmailAddressParser();
$email = $parser->parse('email@example.com');
// $email instanceof \PhpExtended\Email\EmailAddress
or, for headers of requests :
use PhpExtended\Email\MailboxGroupListParser;
$parser = new MailboxGroupListParser();
$list = $parser->parse('Group: Toto toto@example.com; Group2: toto2@example.com, "Tata \"" tata@example.com');
// $list instanceof \PhpExtended\Email\MailboxGroupList
echo $list->collectEmailAddresses();
// echo "toto@example.com, toto2@example.com, tata@example.com"
Test data
This library was tested against the following data sets:
- https://gist.github.com/cjaoude/fd9910626629b53c4d25
- https://github.com/dominicsayers/isemail/blob/master/test/tests.xml
- https://en.wikipedia.org/wiki/Email_address
If you can find other data sets to test against, just file an issue and i will try to test this library against it.
License
MIT (See license file).