PHP code example of f500 / swiftmailer-sparkpost

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

    

f500 / swiftmailer-sparkpost example snippets


$transport = SwiftSparkPost\Transport::newInstance('API-KEY');
$mailer    = Swift_Mailer::newInstance($transport);

$message = Swift_Message::newInstance()
    ->setFrom('[email protected]', 'Me')
    ->setTo(['[email protected]' => 'John Doe', '[email protected]'])
    ->setSubject('...')
    ->setBody('...');

$sent = $mailer->send($message);

$message = SwiftSparkPost\Message::newInstance()
    ->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(['...']);

$config    = SwiftSparkPost\Configuration::newInstance();
$transport = SwiftSparkPost\Transport::newInstance('API-KEY', $config);
$mailer    = Swift_Mailer::newInstance($transport);

$config = SwiftSparkPost\Configuration::newInstance()
    ->setRecipientOverride('[email protected]');

$config = SwiftSparkPost\Configuration::newInstance()
    ->setRecipientOverride('[email protected]')
    ->setOverrideGmailStyle(true);

$config = SwiftSparkPost\Configuration::newInstance()
    ->setOptions([
        SwiftSparkPost\Option::TRANSACTIONAL    => false,
        SwiftSparkPost\Option::OPEN_TRACKING    => false,
        SwiftSparkPost\Option::CLICK_TRACKING   => false,
        SwiftSparkPost\Option::SANDBOX          => true,
        SwiftSparkPost\Option::SKIP_SUPPRESSION => true,
        SwiftSparkPost\Option::INLINE_CSS       => true,
        SwiftSparkPost\Option::IP_POOL          => 'some-ip-pool',
    ]);

$message = SwiftSparkPost\Message::newInstance()
    ->setOptions(['...']);

$config = SwiftSparkPost\Configuration::newInstance()
    ->setOptions([SwiftSparkPost\Option::IP_POOL => 'some-ip-pool'])
    ->setIpPoolProbability(0.5);