PHP code example of g1ntas / swiftmailer-sparkpost-bundle

1. Go to this page and download the library: Download g1ntas/swiftmailer-sparkpost-bundle 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/ */

    

g1ntas / swiftmailer-sparkpost-bundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Gintko\Swiftmailer\SparkpostBundle\GintkoSwiftmailerSparkpostBundle(),
        );

        // ...
    }

    // ...
}


// ...
 
public function sendEmailAction() 
{
    $mailer = $this->get('mailer');
    
    $message = $mailer->createMessage()
        ->setSubject('test')
        ->setFrom('[email protected]', 'Me')
        ->setTo(['[email protected]' => 'John Doe', '[email protected]'])
        ->setSubject('...')
        ->setBody('...');
    
    $mailer->send($message);
}


// ...
 
public function sendEmailAction() 
{
    
    $mailer = $this->get('mailer');
    
    $message = $mailer->createMessage('sparkpost')
        ->setFrom('[email protected]', 'Me')
        ->setTo(['[email protected]' => 'John Doe', '[email protected]'])
        ->setSubject('...')
        ->setBody('...')
        
        ->setCampaignId('...')
        ->setPerRecipientTags('[email protected]', ['...'])
        ->setMetadata(['...' => '...'])
        ->setPerRecipientMetadata('[email protected]', ['...' => '...'])
        ->setSubstitutionData(['...' => '...'])
        ->setPerRecipientSubstitutionData('[email protected]', ['...' => '...'])
        ->setOptions(['...']);
    
    $mailer->send($message);
}
yaml
gintko_swiftmailer_sparkpost:
    api_key: 'SparkPostApiKey' # : null
        gmail_style: false
    message_options:
        transactional: true
        open_tracking: false
        click_tracking: false
        sandbox: false
        skip_suppression: false
        inline_css: false
        ip_pool: null