php-extended / php-email-address-object
A library that implements the php-extended/php-email-address-interface interface library.
7.0.6
2024-07-31 13:54 UTC
Requires
Requires (Dev)
- dev-master
- 7.0.6
- 7.0.5
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.1.7
- 6.1.6
- 6.1.5
- 6.1.4
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.0
- 5.0.2
- 5.0.1
- 5.0.0
- 4.0.2
- 4.0.1
- 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: 2024-10-01 00:08:48 UTC
README
A library that implements the php-extended/php-email-address-interface library.
Installation
The installation of this library is made via composer and the autoloading of all classes of this library is made through their autoloader.
- Download
composer.phar
from their website. - Then run the following command to install this library as dependency :
php composer.phar php-extended/php-email-address-object ^7
Basic Usage
To use this interface, you may do the following :
use PhpExtended\Domain\Domain;
use PhpExtended\Email\EmailAddress;
use PhpExtended\Email\Mailbox;
use PhpExtended\Email\MailboxGroup;
use PhpExtended\Email\MailboxGroupList;
$email = new EmailAddress('example', new Domain('example.com')); // example@example.com
$email->__toString(); // example@example.com
$mailbox = new Mailbox($email, 'Example, Inc');
$mailbox->__toString(); // "Example, Inc" <example@example.com>
$mailboxList = new MailboxList([$mailbox]);
$mailboxList->__toString(); // "Example, Inc" <example@example.com>
$mailboxGroup = new MailboxGroup($mailboxList, 'All Examples');
$mailboxGroup->__toString(); // "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(); // "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
// Group :
// Toto <toto@example.com>
// Group 2:
// <toto2@example.com>
// Tata " <tata@example.com> // <- The display name is 'Tata "' and is properly quoted and escaped on canonicalRepresentation
echo $list->collectEmailAddresses();
// echoes "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).