Provides Emaillabs integration for Symfony Mailer.
The preferred method of installation is via [Composer][]. Run the following
command to install the package and add it as a requirement to your project's
composer.json
:
composer require shepherdmat/emaillabs-symfony-mailer
If you want to use it in your standard Symfony project, it's easy:
Add parameters to your local .env file:
# .env
MAILER_DSN=emaillabs://yourAppKey:[email protected]
Update services.yaml
# config/services.yaml
services:
Shepherdmat\Symfony\Mailer\Emaillabs\Transport\EmaillabsTransportFactory:
tags: [ 'mailer.transport_factory' ]
Now you can follow example from official Symfony Mailer site.
If you want to send email using standard SymfonyHttpClient as http interface:
// require_once __DIR__ . './vendor/autoload.php';
use Shepherdmat\Mailer\Emaillabs\Transport\EmaillabsApiTransport;
use Shepherdmat\Mailer\Emaillabs\Transport\EmaillabsTransportFactory;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mime\Email;
// Your active host account (https://panel.emaillabs.net.pl/pl/smtp).
$host = 'YOUR_ACCOUNT.smtp';
// Your App Key (https://panel.emaillabs.net.pl/pl/site/api).
$appKey = 'XXXXXXX';
// Your Secret Key (https://panel.emaillabs.net.pl/pl/site/api).
$appSecret = 'YYYYYYY';
$transportFactory = new EmaillabsTransportFactory(null, HttpClient::create());
$dsn = new Dsn(EmaillabsTransportFactory::SCHEME, $host, $appKey, $appSecret);
$mailer = new Mailer($transportFactory->create($dsn));
$message = (new Email())
->from('[email protected]')
->to('[email protected]')
->subject('Message title')
->html('<b>HTML message content</b>')
->text('Text message content')
// Attachments are handled by default.
->attachFromPath('./path/to/attachment')
->embedFromPath('./path/to/attachment', 'embed_tag');
// If you want to pass some api parameters, use dedicated headers.
// (https://dev.emaillabs.io/#api-Send-new_sendmail)
$message->getHeaders()
// Comma-separated list of tags.
->addTextHeader(EmaillabsApiTransport::HEADER_TAGS, 'tag1,tag2,tag3')
// Custom template ID.
->addTextHeader(EmaillabsApiTransport::HEADER_TEMPLATE, 'template_id')
// Custom return path.
->addTextHeader(EmaillabsApiTransport::HEADER_RETURN_PATH, 'return_path');
$mailer->send($message);
This bundle is under the MIT license.
For the whole copyright, see the LICENSE file distributed with this source code.