PHP code example of php-dto / email-address

1. Go to this page and download the library: Download php-dto/email-address library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

php-dto / email-address example snippets



use \PhpDto\EmailAddress\EmailAddress;
use \PhpDto\EmailAddress\Exception\InvalidEmailAddressException;

$email = new EmailAddress(' [email protected] '); //spaces will be trimmed

echo $email->get();              //will print '[email protected]'
echo (string) $email;            //will print '[email protected]'

echo $email->getUsername();      //will print 'mail'
echo $email->getHostname();      //will print 'example.com'

echo json_encode([$email]);      //will print '["[email protected]"]'


new EmailAddress('example.com'); //will throw InvalidEmailAddressException (validate by FILTER_VALIDATE_EMAIL)
shell script
composer