https://github.com/firesphere/silverstripe-mailjet-mailer
Send emails from Silverstripe Framework via Mailjet
https://github.com/firesphere/silverstripe-mailjet-mailer
Last synced: 11 months ago
JSON representation
Send emails from Silverstripe Framework via Mailjet
- Host: GitHub
- URL: https://github.com/firesphere/silverstripe-mailjet-mailer
- Owner: Firesphere
- License: gpl-3.0
- Created: 2023-01-29T08:55:46.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-29T00:55:09.000Z (over 2 years ago)
- Last Synced: 2025-06-22T04:05:56.209Z (about 1 year ago)
- Language: PHP
- Size: 34.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: contributing.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Silverstripe Mailjet Mailer
[GPL v3 or later](LICENSE.md)
Simple mailer module that uses Mailjet API to send emails.
## Requirements
* silverstripe/cms ^4.3.x
* silverstripe/framework ^4.3.x
* mailjet/mailjet-apiv3-php "^1.5.8
## Installation
```bash
composer require firesphere/mailjet-mailer
```
## Configuration
Add the following to your `.env`:
```dotenv
SS_MAILJET_KEY="YOURMAILJETKEY"
SS_MAILJET_SECRET="YOURMAILJETSECRET"
```
## Usage
Simply use the Email class provided by SilverStripe framework:
```php
$email = new SilverStripe\Control\Email\Email();
$email->setFrom('from@example.com', 'John Doe');
$email->setTo('to@example.com', 'Jane Doe');
$email->setSubject('This is a test email');
$email->setBody('Hello there, this was sent using Mailjet');
$email->addAttachment('path/to/file.pdf', 'document.pdf');
$email->send();
```
That should be all there is to it.
### DEV usage
If, in dev mode, you still want to use the Mailjet Mailer, but
not want to send actual emails, set the `send` flag to `false`
Via PHP:
```php
new \Firesphere\Mailjet\Service\MailjetMailer(false);
```
or
```php
$mailer = (new \Firesphere\Mailjet\Service\MailjetMailer())->setSend(false);
```
Via YML:
```yaml
SilverStripe\Core\Injector\Injector:
Firesphere\Mailjet\Service\MailjetMailer:
constructor:
- false
```
### Use SandboxMode
Another option to avoid emails actively being sent, is using SandboxMode.
This will go through the entire process of Mailjet, except that Mailjet will not
actively send the emails, but respond as if it did.
Ways to set Sandbox mode:
```php
$mailer = (new \Firesphere\Mailjet\Service\MailjetMailer())->setSandbox(true);
```
```yaml
SilverStripe\Core\Injector\Injector:
Firesphere\Mailjet\Service\MailjetMailer:
constructor:
- true
- true
```
## Advanced usage
Mailjet allows to send multiple emails in a single request.
To do this, use the MailjetMailer directly and give it an array of Email objects.
E.g.
```php
$mails = [
$mail1 = Email::create('to@example.com', 'from@example.com', 'Subject', 'Body'); //
$mail2 = Email::create('to@example.com', 'from@example.com', 'Subject', 'Body'); //
];
(new \Firesphere\Mailjet\Service\MailjetMailer())->send($mails);
```