Git Product home page Git Product logo

swiftmailer-sparkpost's Introduction

SwiftMailer SparkPost Transport

Build Status Code Coverage Scrutinizer Code Quality

A SwiftMailer transport implementation for the SparkPost API.

It uses the official SparkPost PHP library.

It adds support for some SparkPost specific features to SwiftMailer messages.

Installation

composer require f500/swiftmailer-sparkpost

Usage

$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);

Specialized messages

$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(['...']);

Configuration

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

Override recipients

Override all To, Cc and Bcc addresses, but leave name and per-recipient properties intact.

[email protected] becomes [email protected].

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

Gmail style

[email protected] becomes [email protected].

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

Options for all messages

$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',
    ]);

These options are also available for messages, where they take precedence over the configured options.

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

IP pool probability

Add a probability factor to enable the IP pool only for a percentage of messages sent. 0 will never use the IP pool, 1 will always use it.

Can be used to facilitate an IP warming process.

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

License

Copyright 2017 Future500 B.V.

swiftmailer-sparkpost's People

Contributors

comur avatar jaspernbrouwer avatar thewunder avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.