Skip to content

Commit 6a3715f

Browse files
committed
Add examples for cc/bcc
2 parents 9754ffb + 156c144 commit 6a3715f

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* For a more detailed explanation of how cc/bcc work with SparkPost, please
5+
* check out this article: https://support.sparkpost.com/customer/portal/articles/1948014
6+
*/
7+
8+
namespace Examples\Transmisson;
9+
10+
require_once dirname(__FILE__).'/../bootstrap.php';
11+
12+
//pull in API key config
13+
$configFile = file_get_contents(dirname(__FILE__).'/../example-config.json');
14+
$config = json_decode($configFile, true);
15+
16+
use SparkPost\SparkPost;
17+
use GuzzleHttp\Client;
18+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
19+
20+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
21+
$sparky = new SparkPost($httpAdapter, ['key' => $config['api-key']]);
22+
23+
try {
24+
$results = $sparky->transmission->send([
25+
'from' => [
26+
'name' => 'From Envelope',
27+
'email' => '[email protected]',
28+
],
29+
'html' => '<p>An example email using bcc with SparkPost to the {{recipient_type}} recipient.</p>',
30+
'text' => 'An example email using bcc with SparkPost to the {{recipient_type}} recipient.',
31+
'subject' => 'Example email using bcc',
32+
'recipients' => [
33+
[
34+
'address' => [
35+
'name' => 'Original Recipient',
36+
'email' => '[email protected]',
37+
],
38+
'substitution_data' => [
39+
'recipient_type' => 'Original'
40+
]
41+
],
42+
[
43+
'address' => [
44+
'email' => '[email protected]',
45+
'header_to' => '"Original Recipient" <[email protected]>',
46+
],
47+
'substitution_data' => [
48+
'recipient_type' => 'BCC'
49+
]
50+
],
51+
],
52+
]);
53+
echo 'Congrats! You sent an email with bcc using SparkPost!';
54+
} catch (\Exception $exception) {
55+
echo $exception->getAPIMessage()."\n";
56+
echo $exception->getAPICode()."\n";
57+
echo $exception->getAPIDescription()."\n";
58+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* For a more detailed explanation of how cc/bcc work with SparkPost, please
5+
* check out this article: https://support.sparkpost.com/customer/portal/articles/1948014
6+
*/
7+
8+
namespace Examples\Transmisson;
9+
10+
require_once dirname(__FILE__).'/../bootstrap.php';
11+
12+
//pull in API key config
13+
$configFile = file_get_contents(dirname(__FILE__).'/../example-config.json');
14+
$config = json_decode($configFile, true);
15+
16+
use SparkPost\SparkPost;
17+
use GuzzleHttp\Client;
18+
use Ivory\HttpAdapter\Guzzle6HttpAdapter;
19+
20+
$httpAdapter = new Guzzle6HttpAdapter(new Client());
21+
$sparky = new SparkPost($httpAdapter, ['key' => $config['api-key']]);
22+
23+
try {
24+
$results = $sparky->transmission->send([
25+
'from' => [
26+
'name' => 'From Envelope',
27+
'email' => '[email protected]',
28+
],
29+
'html' => '<p>An example email using cc with SparkPost to the {{recipient_type}} recipient.</p>',
30+
'text' => 'An example email using cc with SparkPost to the {{recipient_type}} recipient.',
31+
'subject' => 'Example email using cc',
32+
'recipients' => [
33+
[
34+
'address' => [
35+
'name' => 'Original Recipient',
36+
'email' => '[email protected]',
37+
],
38+
'substitution_data' => [
39+
'recipient_type' => 'Original'
40+
]
41+
],
42+
[
43+
'address' => [
44+
'name' => 'Carbon Copy Recipient',
45+
'email' => '[email protected]',
46+
'header_to' => '"Original Recipient" <[email protected]>',
47+
],
48+
'substitution_data' => [
49+
'recipient_type' => 'CC'
50+
]
51+
],
52+
],
53+
'customHeaders' => [
54+
'CC' => '"Carbon Copy Recipient" <[email protected]>'
55+
]
56+
]);
57+
echo 'Congrats! You sent an email with cc using SparkPost!';
58+
} catch (\Exception $exception) {
59+
echo $exception->getAPIMessage()."\n";
60+
echo $exception->getAPICode()."\n";
61+
echo $exception->getAPIDescription()."\n";
62+
}

0 commit comments

Comments
 (0)