summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRich Leland <rich.leland@messagesystems.com>2016-05-20 09:26:30 -0400
committerRich Leland <rich.leland@messagesystems.com>2016-05-20 09:26:30 -0400
commitaf5169612d4fe02824383cd8e8fdbe0a108ff246 (patch)
treefc612c29e555ba53e58bbbdb7da1afc093c9d1d7
parent6a3715fa492267fc2ef67f65a4dffbf2c85dec9f (diff)
downloadphp-sparkpost-af5169612d4fe02824383cd8e8fdbe0a108ff246.zip
php-sparkpost-af5169612d4fe02824383cd8e8fdbe0a108ff246.tar.gz
php-sparkpost-af5169612d4fe02824383cd8e8fdbe0a108ff246.tar.bz2
Add example for unwrapped transmissions call
-rw-r--r--examples/unwrapped/create_transmission.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/examples/unwrapped/create_transmission.php b/examples/unwrapped/create_transmission.php
new file mode 100644
index 0000000..f19ee6e
--- /dev/null
+++ b/examples/unwrapped/create_transmission.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace Examples\Unwrapped;
+
+require_once dirname(__FILE__).'/../bootstrap.php';
+
+//pull in API key config
+$configFile = file_get_contents(dirname(__FILE__).'/../example-config.json');
+$config = json_decode($configFile, true);
+
+use SparkPost\SparkPost;
+use GuzzleHttp\Client;
+use Ivory\HttpAdapter\Guzzle6HttpAdapter;
+
+$httpAdapter = new Guzzle6HttpAdapter(new Client());
+$sparky = new SparkPost($httpAdapter, ['key' => $config['api-key']]);
+
+try {
+ // define the endpoint
+ $sparky->setupUnwrapped('transmissions');
+
+ $message = [
+ 'recipients' => [
+ [
+ 'address' => [
+ 'email' => 'john.doe@example.com',
+ ]
+ ]
+ ],
+ 'content' => [
+ 'from' => [
+ 'name' => 'From Envelope',
+ 'email' => 'from@sparkpostbox.com',
+ ],
+ 'html' => '<p>Hello World!</p>',
+ 'text' => 'Hello World!',
+ 'subject' => 'Example Email'
+ ]
+ ];
+ $results = $sparky->transmissions->create($message);
+ echo 'Congrats! You sent a message using SparkPost!';
+} catch (\Exception $exception) {
+ echo $exception->getAPIMessage()."\n";
+ echo $exception->getAPICode()."\n";
+ echo $exception->getAPIDescription()."\n";
+}
+