Skip to content

Commit 9cf58b8

Browse files
committed
wrote examples for transmissions
1 parent ce821d6 commit 9cf58b8

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
/**
14+
* configure options in example-options.json
15+
*/
16+
$sparky = new SparkPost($httpClient, $options);
17+
18+
$promise = $sparky->transmissions->post([
19+
'content' => [
20+
'from'=> [
21+
'name' => 'SparkPost Team',
22+
'email' => 'from@sparkpostbox.com'
23+
],
24+
'subject'=>'First Mailing From PHP',
25+
'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
26+
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!'
27+
],
28+
'substitution_data'=> ['name'=>'YOUR_FIRST_NAME'],
29+
'recipients'=> [
30+
[ 'address' => 'YOUR_NAME <YOUR_EMAIL>' ]
31+
]
32+
]);
33+
34+
try {
35+
$response = $promise->wait();
36+
echo $response->getStatusCode() . "\n";
37+
print_r($response->getBody());
38+
} catch (Exception $e) {
39+
echo $e->getCode() . "\n";
40+
echo $e->getMessage() . "\n";
41+
}
42+
?>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
/**
14+
* configure options in example-options.json
15+
*/
16+
$sparky = new SparkPost($httpClient, $options);
17+
18+
$promise = $sparky->transmissions->post([
19+
'content' => [
20+
'from'=> [
21+
'name' => 'SparkPost Team',
22+
'email' => 'from@sparkpostbox.com'
23+
],
24+
'subject'=>'First Mailing From PHP',
25+
'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
26+
'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!'
27+
],
28+
'substitution_data'=> ['name'=>'YOUR_FIRST_NAME'],
29+
'recipients'=> [
30+
[ 'address' => 'YOUR_NAME <YOUR_EMAIL>' ]
31+
],
32+
'cc'=> [
33+
[ 'address' => 'ANOTHER_NAME <ANOTHER_EMAIL>' ]
34+
],
35+
'bcc'=> [
36+
[ 'address' => 'AND_ANOTHER_NAME <AND_ANOTHER_EMAIL>' ]
37+
]
38+
]);
39+
40+
try {
41+
$response = $promise->wait();
42+
echo $response->getStatusCode() . "\n";
43+
print_r($response->getBody());
44+
} catch (Exception $e) {
45+
echo $e->getCode() . "\n";
46+
echo $e->getMessage() . "\n";
47+
}
48+
?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
/**
14+
* configure options in example-options.json
15+
*/
16+
$sparky = new SparkPost($httpClient, $options);
17+
18+
$promise = $sparky->transmissions->delete('TRANSMISSION_ID');
19+
20+
try {
21+
$response = $promise->wait();
22+
echo $response->getStatusCode() . "\n";
23+
print_r($response->getBody());
24+
} catch (Exception $e) {
25+
echo $e->getCode() . "\n";
26+
echo $e->getMessage() . "\n";
27+
}
28+
?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
/**
14+
* configure options in example-options.json
15+
*/
16+
$sparky = new SparkPost($httpClient, $options);
17+
18+
$promise = $sparky->transmissions->get();
19+
20+
try {
21+
$response = $promise->wait();
22+
echo $response->getStatusCode() . "\n";
23+
print_r($response->getBody());
24+
} catch (Exception $e) {
25+
echo $e->getCode() . "\n";
26+
echo $e->getMessage() . "\n";
27+
}
28+
?>

0 commit comments

Comments
 (0)