2020-05-12 17:16:40 +02:00
|
|
|
# laravel-mail
|
2020-04-09 12:55:07 +02:00
|
|
|
|
2020-05-07 15:37:48 +02:00
|
|
|
The Bluescale Mail package allows you to send Bluescale Mail templates using Laravel notifications system.
|
2020-04-09 12:55:07 +02:00
|
|
|
|
2020-04-09 17:57:21 +02:00
|
|
|
## Installation
|
2020-04-09 12:55:07 +02:00
|
|
|
|
2020-05-07 15:37:48 +02:00
|
|
|
First in your composer.json, add:
|
2020-04-09 12:55:07 +02:00
|
|
|
|
2020-05-07 15:37:48 +02:00
|
|
|
```
|
2020-04-09 16:00:19 +02:00
|
|
|
"require": {
|
2020-05-12 17:16:40 +02:00
|
|
|
"bluescale/laravel-bmail": "dev-master"
|
2020-04-10 13:11:40 +02:00
|
|
|
}
|
2020-04-09 16:00:19 +02:00
|
|
|
|
|
|
|
"repositories": [
|
2020-05-12 17:16:40 +02:00
|
|
|
{
|
|
|
|
"type": "vcs",
|
|
|
|
"url": "https://git.bluesquare.io/bluescale/laravel-bmail"
|
|
|
|
}
|
2020-04-10 13:11:40 +02:00
|
|
|
]
|
2020-04-09 16:00:19 +02:00
|
|
|
```
|
|
|
|
|
2020-05-12 17:16:40 +02:00
|
|
|
Next, install the package:
|
2020-04-09 16:00:19 +02:00
|
|
|
|
|
|
|
```bash
|
2020-04-09 17:43:19 +02:00
|
|
|
composer update bluescale/laravel-bmail
|
2020-04-09 12:55:07 +02:00
|
|
|
```
|
2020-04-09 17:21:16 +02:00
|
|
|
|
2020-05-12 17:16:40 +02:00
|
|
|
If you want to customize the config system:
|
2020-04-09 17:21:16 +02:00
|
|
|
|
|
|
|
```bash
|
|
|
|
php artisan vendor:publish
|
|
|
|
```
|
|
|
|
|
2020-05-07 15:37:48 +02:00
|
|
|
Finally, copy your API key from Bluescale Mail (Templates section), and add it in your `.env`:
|
2020-04-09 17:43:19 +02:00
|
|
|
|
|
|
|
```bash
|
2020-05-07 15:37:48 +02:00
|
|
|
BMAIL_API_KEY=your_api_key
|
2020-04-27 17:53:30 +02:00
|
|
|
```
|
|
|
|
|
2020-05-07 15:37:48 +02:00
|
|
|
You may also want to use your own API:
|
2020-04-27 17:53:30 +02:00
|
|
|
|
|
|
|
```bash
|
|
|
|
BMAIL_API_URL=https://bluescale.email/api/project/template/send
|
2020-04-09 17:43:19 +02:00
|
|
|
```
|
|
|
|
|
2020-04-09 17:57:21 +02:00
|
|
|
## Usage
|
|
|
|
|
2020-05-07 15:37:48 +02:00
|
|
|
First, create a new notification or use an existing one:
|
2020-04-14 18:26:08 +02:00
|
|
|
|
|
|
|
```bash
|
2020-05-07 15:37:48 +02:00
|
|
|
php artisan make:notification MyAwesomeNotification
|
2020-04-14 18:26:08 +02:00
|
|
|
```
|
|
|
|
|
2020-05-12 17:16:40 +02:00
|
|
|
Add BluescaleMailChannel in the `via()` method:
|
2020-04-14 18:26:08 +02:00
|
|
|
|
2020-05-07 15:37:48 +02:00
|
|
|
```php
|
2020-05-12 17:16:40 +02:00
|
|
|
return [BluescaleMailChannel::class];
|
2020-04-14 18:26:08 +02:00
|
|
|
```
|
|
|
|
|
2020-04-14 18:29:13 +02:00
|
|
|
Then, create a 'toTemplate()' method, in which you specify your template fields :
|
2020-04-14 18:26:08 +02:00
|
|
|
|
2020-05-07 15:37:48 +02:00
|
|
|
```php
|
2020-04-14 18:26:08 +02:00
|
|
|
public function toTemplate($notifiable)
|
|
|
|
{
|
2020-05-12 17:16:40 +02:00
|
|
|
return (new BluescaleMailTemplate("my-template-id"))
|
2020-05-07 15:37:48 +02:00
|
|
|
->sender("john.doe@gmail.com", "John OPTIONAL") // OPTIONAL
|
|
|
|
->replyTo("jean.grey@gmail.com", "Jean OPTIONAL") // OPTIONAL
|
2020-04-14 18:26:08 +02:00
|
|
|
->recipients([
|
|
|
|
[
|
|
|
|
"elvis@gmail.com", [
|
2020-05-07 15:37:48 +02:00
|
|
|
"name" => "Elvis" // OPTIONAL,
|
|
|
|
"parameters" => ["key" => "value"] // OPTIONAL
|
2020-04-14 18:26:08 +02:00
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"robert@gmail.com"
|
2020-04-10 13:10:48 +02:00
|
|
|
]
|
2020-04-14 18:26:08 +02:00
|
|
|
])
|
2020-05-07 15:37:48 +02:00
|
|
|
->addRecipient("edward@gmail.com") // OPTIONAL
|
|
|
|
->parameters(["key" => "value", "key" => "value"]) // OPTIONAL
|
|
|
|
->addParameter("key", "value") // OPTIONAL
|
|
|
|
;
|
2020-04-14 18:26:08 +02:00
|
|
|
}
|
2020-04-09 17:57:21 +02:00
|
|
|
```
|
|
|
|
|
2020-05-07 15:37:48 +02:00
|
|
|
The $notifiable is automaticaly added as recipient.
|
2020-04-28 18:07:20 +02:00
|
|
|
|
|
|
|
|
2020-05-07 15:37:48 +02:00
|
|
|
In your controller, you can now send your template:
|
2020-04-14 18:26:08 +02:00
|
|
|
|
2020-05-07 15:37:48 +02:00
|
|
|
```php
|
|
|
|
User::first()->notify(new MyAwesomeNotification);
|
2020-04-09 17:57:21 +02:00
|
|
|
```
|
|
|
|
|
2020-04-09 17:21:16 +02:00
|
|
|
|