Skip to content

Commit 36afb9f

Browse files
authored
added attachment example
added attachment example
2 parents f4cb526 + 6bcfbd1 commit 36afb9f

20 files changed

+69
-66
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
.settings
44
.buildpath
55
test/output/
6-
examples/example-options.json
76
.idea
87
/composer.phar
98
test.php

composer.json

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
],
1010
"minimum-stability": "stable",
1111
"scripts": {
12-
"post-install-cmd": "./post-install.sh",
13-
"post-update-cmd": "./post-install.sh",
1412
"test": "./vendor/bin/phpunit",
1513
"fix-style": "php-cs-fixer fix ."
1614
},

examples/bootstrap.php

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
<?php
22

33
require_once dirname(__FILE__).'/../vendor/autoload.php';
4-
5-
//pull in library options
6-
$optionsFile = file_get_contents(dirname(__FILE__).'/example-options.json');
7-
$options = json_decode($optionsFile, true);

examples/message-events/get_message_events.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY",]);
1714

1815
$promise = $sparky->request('GET', 'message-events', [
1916
'campaign_ids' => 'CAMPAIGN_ID',

examples/templates/create_template.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->request('POST', 'templates', [
1916
'name' => 'PHP example template',

examples/templates/delete_template.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->request('DELETE', 'templates/TEMPLATE_ID');
1916

examples/templates/get_all_templates.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->request('GET', 'templates');
1916

examples/templates/get_template.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->request('GET', 'templates/TEMPLATE_ID?draft=true');
1916

examples/templates/preview_template.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->request('POST', 'templates/TEMPLATE_ID/preview?draft=true', [
1916
'substitution_data' => [

examples/templates/update_template.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->request('PUT', 'templates/TEMPLATE_ID', [
1916
'options' => [

examples/transmissions/create_transmission.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->transmissions->post([
1916
'content' => [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Examples\Transmissions;
4+
5+
require dirname(__FILE__).'/../bootstrap.php';
6+
7+
use SparkPost\SparkPost;
8+
use GuzzleHttp\Client;
9+
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
10+
11+
$httpClient = new GuzzleAdapter(new Client());
12+
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
14+
15+
$filePath = dirname(__FILE__).'/';
16+
$fileName = 'sparkpost.png';
17+
$fileType = mime_content_type($filePath.$fileName);
18+
$fileData = base64_encode(file_get_contents($filePath.$fileName));
19+
20+
$promise = $sparky->transmissions->post([
21+
'content' => [
22+
'from' => [
23+
'name' => 'SparkPost Team',
24+
'email' => '[email protected]',
25+
],
26+
'subject' => 'Mailing With Attachment From PHP',
27+
'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent an email with an attachment!</p></body></html>',
28+
'text' => 'Congratulations, {{name}}! You just sent an email with an attachment',
29+
'attachments' => [
30+
[
31+
'name' => $fileName,
32+
'type' => $fileType,
33+
'data' => $fileData,
34+
],
35+
],
36+
],
37+
'substitution_data' => ['name' => 'YOUR_FIRST_NAME'],
38+
'recipients' => [
39+
[
40+
'address' => [
41+
'name' => 'YOUR_NAME',
42+
'email' => 'YOUR_EMAIL',
43+
],
44+
],
45+
],
46+
]);
47+
48+
try {
49+
$response = $promise->wait();
50+
echo $response->getStatusCode()."\n";
51+
print_r($response->getBody())."\n";
52+
} catch (\Exception $e) {
53+
echo $e->getCode()."\n";
54+
echo $e->getMessage()."\n";
55+
}

examples/transmissions/create_transmission_with_cc_and_bcc.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->transmissions->post([
1916
'content' => [

examples/transmissions/create_transmission_with_recipient_list.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->transmissions->post([
1916
'content' => [

examples/transmissions/create_transmission_with_template.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->transmissions->post([
1916
'content' => ['template_id' => 'TEMPLATE_ID'],

examples/transmissions/delete_transmission.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->transmissions->delete('TRANSMISSION_ID');
1916

examples/transmissions/get_all_transmissions.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->transmissions->get();
1916

examples/transmissions/get_transmission.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
$httpClient = new GuzzleAdapter(new Client());
1212

13-
/*
14-
* configure options in example-options.json
15-
*/
16-
$sparky = new SparkPost($httpClient, $options);
13+
$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY"]);
1714

1815
$promise = $sparky->transmissions->get('TRANSMISSION_ID');
1916

examples/transmissions/sparkpost.png

6.79 KB
Loading

post-install.sh

-3
This file was deleted.

0 commit comments

Comments
 (0)