Skip to content

Commit af51696

Browse files
author
Rich Leland
committed
Add example for unwrapped transmissions call
1 parent 6a3715f commit af51696

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Examples\Unwrapped;
4+
5+
require_once dirname(__FILE__).'/../bootstrap.php';
6+
7+
//pull in API key config
8+
$configFile = file_get_contents(dirname(__FILE__).'/../example-config.json');
9+
$config = json_decode($configFile, true);
10+
11+
use SparkPost\SparkPost;
12+
use GuzzleHttp\Client;
13+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
14+
15+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
16+
$sparky = new SparkPost($httpAdapter, ['key' => $config['api-key']]);
17+
18+
try {
19+
// define the endpoint
20+
$sparky->setupUnwrapped('transmissions');
21+
22+
$message = [
23+
'recipients' => [
24+
[
25+
'address' => [
26+
'email' => '[email protected]',
27+
]
28+
]
29+
],
30+
'content' => [
31+
'from' => [
32+
'name' => 'From Envelope',
33+
'email' => '[email protected]',
34+
],
35+
'html' => '<p>Hello World!</p>',
36+
'text' => 'Hello World!',
37+
'subject' => 'Example Email'
38+
]
39+
];
40+
$results = $sparky->transmissions->create($message);
41+
echo 'Congrats! You sent a message using SparkPost!';
42+
} catch (\Exception $exception) {
43+
echo $exception->getAPIMessage()."\n";
44+
echo $exception->getAPICode()."\n";
45+
echo $exception->getAPIDescription()."\n";
46+
}
47+

0 commit comments

Comments
 (0)