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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<?php
namespace Examples\Transmisson;
require_once (dirname(__FILE__).'/../bootstrap.php');
use SparkPost\SparkPost;
use SparkPost\Transmission;
use GuzzleHttp\Client;
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
$key = 'YOUR API KEY';
$httpAdapter = new Guzzle6HttpAdapter(new Client());
SparkPost::configure($httpAdapter, ['key'=>$key]);
// TODO: update all from emails to = sandbox domain
try{
$results = Transmission::send([
"campaign"=>"my-campaign",
"metadata"=>[
"sample_campaign"=>true,
"type"=>"these are custom fields"
],
"substitutionData"=>[
"name"=>"Test Name"
],
"description"=>"my description",
"replyTo"=>"reply@test.com",
"customHeaders"=>[
"X-Custom-Header"=>"Sample Custom Header"
],
"trackOpens"=>false,
"trackClicks"=>false,
"from"=>"From Envelope <from@sparkpostbox.com>",
"html"=>"<p>Hello World! Your name is: {{name}}</p>",
"text"=>"Hello World!",
"subject"=>"Example Email: {{name}}",
"recipients"=>[
[
"address"=>[
"email"=>"john.doe@example.com"
]
]
]
]);
var_dump($results);
echo 'Congrats you can use your SDK!';
} catch (\Exception $exception) {
echo $exception->getMessage();
}
?>
|