locomotivemtl / charcoal-email
Email sending and queueing for Charcoal
Installs: 13 973
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 13
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- ext-pdo: *
- locomotivemtl/charcoal-app: ~0.6
- locomotivemtl/charcoal-config: ~0.6
- locomotivemtl/charcoal-queue: ~0.5
- phpmailer/phpmailer: ~6.0
- psr/log: ^1.0
- seld/jsonlint: ^1.7
Requires (Dev)
- mustache/mustache: ^2.11
- php-coveralls/php-coveralls: ~1.0
- phpstan/phpstan: ^0.12.36
- phpunit/phpunit: ^5.7 || ^6.5
- pimple/pimple: ~3.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-11-16 14:06:43 UTC
README
Sending emails (with PHPMailer) and queue management.
How to install
The preferred (and only supported) way of installing charcoal-email is with composer:
★ composer require locomotivemtl/charcoal-email
Dependencies
PHP 5.6+
- PHP 7.3+ is highly recommended
phpmailer/phpmailer
locomotivemtl/charcoal-config
locomotivemtl/charcoal-app
Optional dependencies
pimple/pimple
- Dependency injection Container (required for the Service Provider)
👉 All optional depedencies are required for development. All other development dependencies, which are optional when using charcoal-email in a project, are described in the Development section of this README file.
Usage
$email = $container['email']; $email->setData([ 'campaign' => 'Campaign identifier' 'to' => [ 'recipient@example.com', '"Some guy" <someguy@example.com>', [ 'name' => 'Other guy', 'email' => 'otherguy@example.com' ] ], 'bcc' => 'shadow@example.com' 'from' => '"Company inc." <company.inc@example.com>', 'reply_to' => [ 'name' => 'Jack CEO', 'email' => 'jack@example.com' ], 'subject' => $this->translator->trans('Email subject'), 'template_ident' => 'foo/email/default-email' 'attachments' => [ 'foo/bar.pdf', 'foo/baz.pdf' ] ]); $email->send(); // Alternately, to send at a later date / use the queue system: $email->queue('in 5 minutes');
Email Config
The entire email system can be configured from the main app config, in the email
config key.
{ "email": { "smtp": true, "smtp_hostname": "smtp.example.com", "smtp_port": 25, "smtp_security": "tls", "smtp_username": "user@example.com", "smtp_password": "password", "default_from": "webproject@example.com", "default_reply_to": "webproject@example.com", "default_track": false, "default_log": true } }
Service Provider
All email services can be quickly registered to a (pimple
) container with \Charcoal\Email\ServiceProvider\EmailServiceProvider
.
Provided services:
1 \Charcoal\Email\Email
.
2 Charcoal\Factory\FactoryInterface
.
Also available are the following helpers:
3 \Charcoal\Email\EmailConfig
.
4 \Charcoal\View\ViewInterface
.
👉 For charcoal projects, simply add this provider to your config to enable:
{ "service_providers": { "charcoal/email/service-provider/email": {} } }
Service dependencies
For the email service provider to work properly, the following services are expected to e registerd on the same container:
config
view
Development
To install the development environment:
★ composer install --prefer-source
To run the scripts (phplint, phpcs and phpunit):
★ composer test
Development dependencies
phpunit/phpunit
squizlabs/php_codesniffer
satooshi/php-coveralls
Continuous Integration
Coding Style
The Charcoal-Email module follows the Charcoal coding-style:
- PSR-1
- PSR-2
- PSR-4, autoloading is therefore provided by Composer.
- phpDocumentor comments.
- Read the phpcs.xml file for all the details on code style.
Coding style validation / enforcement can be performed with
composer phpcs
. An auto-fixer is also available withcomposer phpcbf
.
Authors
License
Charcoal is licensed under the MIT license. See LICENSE for details.