File tree 1 file changed +47
-0
lines changed
1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
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
+
27
+ ]
28
+ ]
29
+ ],
30
+ 'content ' => [
31
+ 'from ' => [
32
+ 'name ' => 'From Envelope ' ,
33
+
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
+
You can’t perform that action at this time.
0 commit comments