PHP code example of tlamedia / sparkpost-bundle
1. Go to this page and download the library: Download tlamedia/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/ */
tlamedia / sparkpost-bundle example snippets
// config/bundles.php
return [
//...
Tla\SparkPostBundle\TlaSparkPostBundle::class => ['all' => true],
//...
];
class SomeController extends Controller
{
public function sendAction()
{
$sparky = $this->getContainer()->get('tla_spark_post.api_client');
$promise = $sparky->transmissions->post([
'content' => [
'from' => [
'name' => 'YOUR_NAME',
'email' => 'YOUR_EMAIL',
],
'subject' => 'My first mail using SparkPostBundle',
'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your first mail!</p></body></html>',
'text' => 'Congratulations, {{name}}!! You just sent your first mail!',
],
'substitution_data' => ['name' => 'YOUR_FIRST_NAME'],
'recipients' => [
[
'address' => [
'name' => 'YOUR_NAME',
'email' => 'YOUR_EMAIL',
],
],
],
'cc' => [
[
'address' => [
'name' => 'ANOTHER_NAME',
'email' => 'ANOTHER_EMAIL',
],
],
],
'bcc' => [
[
'address' => [
'name' => 'AND_ANOTHER_NAME',
'email' => 'AND_ANOTHER_EMAIL',
],
],
],
]);
$promise = $sparky->transmissions->get();
try {
$promise->wait();
} catch (\Throwable $t) {
echo $t->getCode()."\n";
echo $t->getMessage()."\n";
}
}
}