hanfrey / sparkpost-bundle
This bundle provides integration with the Sparkpost API library, allowing you to interact with the Sparkpost API from within your Symfony projects
Installs: 7 834
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 1
Forks: 4
Open Issues: 1
Type:symfony-bundle
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ~6.0
- sparkpost/sparkpost: ^1.0
Requires (Dev)
This package is not auto-updated.
Last update: 2024-04-13 16:29:24 UTC
README
Bundle for using Sparkpost in symfony
Installation
Step 1) Get the bundle
composer require hanfrey/sparkpost-bundle
Step 2) Register the bundle
To start using the bundle, register it in your Kernel.
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Hanfrey\SparkpostBundle\HanfreySparkpostBundle(), // ... ); }
Step 3) Configure the default API token to use (mandatory)
Here is an example:
# app/config/config.yml hanfrey_sparkpost: api_token: 1212334ba # replace with your own
Step 4) Example Usage in a controller
$sparky= $this->get("hanfrey_sparkpost.api_client"); try { // Build your email and send it! $results = $sparky->transmission->send([ 'from'=>'From Envelope <from@sparkpostbox.com>', 'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>', 'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!', 'substitutionData'=>['name'=>'YOUR FIRST NAME'], 'subject'=>'First Mailing From PHP', 'recipients'=>[ [ 'address'=>[ 'name'=>'YOUR FULL NAME', 'email'=>'YOUR EMAIL ADDRESS' ] ] ] ]); echo 'Woohoo! You just sent your first mailing!'; } catch (\Exception $err) { echo 'Whoops! Something went wrong'; var_dump($err); }
Documentation
Detailed documentation on how to access each API method can be found in the documentation of the package that this bundle integrates: Sparkpost API library