PHP code example of sunaoka / laravel-ses-template-driver

1. Go to this page and download the library: Download sunaoka/laravel-ses-template-driver library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sunaoka / laravel-ses-template-driver example snippets


'default' => 'sestemplate',

'mailers' => [
    'sestemplate' => [
        'transport' => 'sestemplate',  // or `sesv2template` - When using Amazon SES API v2
    ],
],

'ses' => [
    'key'    => 'your-ses-key',
    'secret' => 'your-ses-secret',
    'region' => 'ses-region',  // e.g. us-east-1
],

'ses' => [
    'key'     => 'your-ses-key',
    'secret'  => 'your-ses-secret',
    'region'  => 'ses-region',  // e.g. us-east-1
    'options' => [
        'ConfigurationSetName' => 'MyConfigurationSet',
        'Tags' => [
            [
                'Name'  => 'foo',
                'Value' => 'bar',
            ],
        ],
    ],
],

use Illuminate\Support\Facades\Mail;
use Sunaoka\LaravelSesTemplateDriver\Mail\SesTemplate;

class Foo
{
    public function sendmail()
    {
        $templateName = 'MyTemplate';
        $templateData = [
            'name' => 'Alejandro',
            'favoriteanimal' => 'alligator',
        ];

        $result = Mail::to('[email protected]')
            ->cc('[email protected]')
            ->bcc('[email protected]')
            ->send(new SesTemplate($templateName, $templateData));
            
        echo $result->getMessageId();  // Message-ID overwritten by Amazon SES
    }
}

use Illuminate\Mail\Mailables\Address;
use Illuminate\Support\Facades\Mail;
use Sunaoka\LaravelSesTemplateDriver\Mail\SesTemplate;
use Sunaoka\LaravelSesTemplateDriver\Mail\SesTemplateOptions;

class Foo
{
    public function sendmail()
    {
        $templateName = 'MyTemplate';
        $templateData = [
            'name' => 'Alejandro',
            'favoriteanimal' => 'alligator',
        ];

        $options = new SesTemplateOptions();
        $options->from(new Address('[email protected]', 'Alejandro Rosalez'))
                ->replyTo(new Address('[email protected]'));

        // Only with Amazon SES API v2 ('transport' is `sesv2template`)
        $options->header('X-Custom-Header1', 'Custom Value 1')
                ->header('X-Custom-Header2', 'Custom Value 2');

        // You can also set it in the constructor.
        $options = new SesTemplateOptions(
            from: new Address('[email protected]', 'Alejandro Rosalez'),
            replyTo: new Address('[email protected]'),
            headers: [
                'X-Custom-Header1' => 'Custom Value 1',
                'X-Custom-Header2' => 'Custom Value 2',
            ],
        );

        $result = Mail::to('[email protected]')
            ->cc('[email protected]')
            ->bcc('[email protected]')
            ->send(new SesTemplate($templateName, $templateData, $options));
            
        echo $result->getMessageId();  // Message-ID overwritten by Amazon SES
    }
}
bash
php artisan ses-template:list-templates --help
bash
php artisan ses-template:list-templates
bash
php artisan ses-template:list-templates --json
json
{
  "TemplatesMetadata": [
    {
      "Name": "MyTemplate",
      "CreatedTimestamp": "2020-11-24T15:01:21+00:00"
    },
    {
      "Name": "MyTemplate2",
      "CreatedTimestamp": "2020-11-24T15:01:25+00:00"
    }
  ]
}
json
{
  "TemplatesMetadata": [
    {
      "TemplateName": "MyTemplate",
      "CreatedTimestamp": "2020-11-24T15:01:21+00:00"
    },
    {
      "TemplateName": "MyTemplate2",
      "CreatedTimestamp": "2020-11-24T15:01:25+00:00"
    }
  ]
}
bash
php artisan ses-template:get-template --help
bash
php artisan ses-template:get-template MyTemplate
bash
php artisan ses-template:get-template MyTemplate --json