blob: ada8ff118e7af03902e689dccbc7e2cbd29c7646 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<?php
namespace Examples\Templates;
require dirname(__FILE__).'/../bootstrap.php';
use SparkPost\SparkPost;
use GuzzleHttp\Client;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
$promise = $sparky->request('POST', 'templates', [
'name' => 'PHP example template',
'content' => [
'from' => 'from@YOUR_DOMAIN',
'subject' => 'Your Subject',
'html' => '<b>Write your message here.</b>',
],
]);
try {
$response = $promise->wait();
echo $response->getStatusCode()."\n";
print_r($response->getBody())."\n";
} catch (\Exception $e) {
echo $e->getCode()."\n";
echo $e->getMessage()."\n";
}
|