You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-17Lines changed: 44 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ The recommended way to install the SparkPost PHP SDK is through composer.
13
13
# Install Composer
14
14
curl -sS https://getcomposer.org/installer | php
15
15
```
16
-
Next, run the Composer command to install the SparkPost PHP SDK:
16
+
Next, run the Composer command to install the SparkPost PHP SDK:
17
17
```
18
18
composer require sparkpost/php-sparkpost
19
19
```
@@ -22,25 +22,53 @@ After installing, you need to require Composer's autoloader:
22
22
require 'vendor/autoload.php';
23
23
```
24
24
25
+
## Setting up a Request Adapter
26
+
Because of dependency collision, we have opted to use a request adapter rather than
27
+
requiring a request library. This means that your application will need to pass in
28
+
a request adapter to the constructor of the SparkPost Library. We use the [Ivory HTTP Adapter] (https://github.com/egeloen/ivory-http-adapter) in SparkPost. Please visit their repo
29
+
for a list of supported adapters. If you don't currently use a request library, you will
30
+
need to require one and create an adapter from it and pass it along. The example below uses the
31
+
GuzzleHttp Client Library.
32
+
33
+
An Adapter can be setup like so:
34
+
```
35
+
use SparkPost\SparkPost;
36
+
use GuzzleHttp\Client;
37
+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
38
+
39
+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
40
+
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);
41
+
```
42
+
25
43
## Getting Started: Your First Mailing
26
44
```
27
-
SparkPost::setConfig(["key"=>"YOUR API KEY"]);
45
+
use SparkPost\SparkPost;
46
+
use GuzzleHttp\Client;
47
+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
48
+
49
+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
50
+
$sparky = new SparkPost($httpAdapter, ['key'=>'YOUR API KEY']);
'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
35
-
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
36
-
'substitutionData'=>array('name'=>'YOUR FIRST NAME'),
37
-
'recipients'=>array(array('address'=>array('name'=>'YOUR FULL NAME', 'email'=>'YOUR EMAIL ADDRESS' )))
38
-
));
39
-
40
-
echo 'Woohoo! You just sent your first mailing!';
41
-
} catch (Exception $err) {
42
-
echo 'Whoops! Something went wrong';
43
-
var_dump($err);
53
+
$results = $sparky->transmission->send([
54
+
'from'=>'From Envelope <from@sparkpostbox.com>',
55
+
'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
56
+
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!',
57
+
'substitutionData'=>array('name'=>'YOUR FIRST NAME')
58
+
'subject'=>'First Mailing From PHP',
59
+
'recipients'=>[
60
+
[
61
+
"address"=>[
62
+
'name'=>'YOUR FULL NAME',
63
+
'email'=>'YOUR EMAIL ADDRESS'
64
+
]
65
+
]
66
+
]
67
+
]);
68
+
echo 'Woohoo! You just sent your first mailing!';
69
+
} catch (\Exception $err) {
70
+
echo 'Whoops! Something went wrong';
71
+
var_dump($err);
44
72
}
45
73
```
46
74
@@ -101,4 +129,3 @@ If you're interested in code coverage, you can add the `--coverage` flag for php
101
129
2. Fork [the repository](http://github.com/SparkPost/php-sparkpost) on GitHub to start making your changes to the **master** branch (or branch off of it).
102
130
3. Write a test which shows that the bug was fixed or that the feature works as expected.
103
131
4. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to [AUTHORS](https://github.com/SparkPost/php-sparkpost/blob/master/AUTHORS.md).
0 commit comments