quartzy / php-email
A domain model for describing emails that is indifferent towards sending methods.
Installs: 9 146
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 13
Forks: 0
Open Issues: 0
Requires
- php: ^7.1
Requires (Dev)
- phpunit/phpunit: ^7.0
README
This is a domain-driven library for defining emails in PHP.
Php Email brings three major benefits over other similar libraries:
- Focusing on new versions of PHP. By using the newer versions of PHP (5.6+) we can leverage great features such as splat parameters and better type hinting.
- Focusing on only the email, instead of transmission. In a domain-driven world, emails can and should exist separately from the delivery mechanism. By separating these concerns, this library decreases the size and complexity of the domain, while giving developers greater flexibility in how they use the library.
- Flexible content definitions. Emails have gone from a simple text string to highly stylized HTML to now just being templates stored in third-party services. Existing libraries do not provide enough flexibility to support everything developers need. Php Email attempts to correct this by creating guidelines for possible email content, but also allowing developers to define what they need.
Install
With Composer
composer require quartzy/php-email
Usage
Building an email with HTML and text content would look like:
<?php use PhpEmail\Attachment\FileAttachment; use PhpEmail\EmailBuilder; use PhpEmail\Content\SimpleContent; $email = EmailBuilder::email() ->withSubject('Welcome!') ->withContent(SimpleContent::text('Start your free trial now!!!')) ->from('me@test.com') ->to('you@yourbusiness.com') ->cc('cc@test.com') ->bcc('bcc@test.com') ->replyTo('reply.to@test.com') ->attach(new FileAttachment('/path/to/my/file.txt')) ->build();
Sending a templated email:
<?php use PhpEmail\EmailBuilder; use PhpEmail\Content\TemplatedContent; $content = new TemplatedContent('my_templates_id', ['firstName' => 'Billy']); $email = EmailBuilder::email() ->withSubject('Welcome!') ->withContent($content) ->from('me@test.com') ->to('you@yourbusiness.com') ->build();
Change log
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email opensource@quartzy.com instead of using the issue tracker.
Credits
License
The Apache License, v2.0. Please see License File for more information.