Bundle for using PeytzSend (Sparkpost) in symfony
Forked from https://github.com/Hanfrey/sparkpost-bundle
composer require peytz/peytzsend-bundle
To start using the bundle, register it in your Kernel.
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Peytz\PeytzsendBundle\PeytzsendBundle(),
// ...
);
}
Here is an example:
# app/config/config.yml
peytz_peytzsend:
api_token: 1212334ba # replace with your own
api_host: api.eu.sparkpost.com
$ps_client = $this->get("peytz_peytzsend.api_client");
try {
// Build your email and send it!
$results = $ps_client->transmission->send([
'from'=>'From Envelope <from@example.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);
}
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