-
Notifications
You must be signed in to change notification settings - Fork 89
/
create_transmission_with_cc_and_bcc.php
66 lines (58 loc) · 1.86 KB
/
create_transmission_with_cc_and_bcc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Examples\Transmissions;
require dirname(__FILE__).'/../bootstrap.php';
use SparkPost\SparkPost;
use GuzzleHttp\Client;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
$httpClient = new GuzzleAdapter(new Client());
// In these examples, fetch API key from environment variable
$sparky = new SparkPost($httpClient, ["key" => getenv('SPARKPOST_API_KEY')]);
// put your own sending domain and test recipient address here
$sending_domain = "steve2-test.trymsys.net";
$your_email = "bob@sink.sparkpostmail.com";
$your_cc = "alice@sink.sparkpostmail.com";
$your_bcc = "charles@sink.sparkpostmail.com";
$promise = $sparky->transmissions->post([
'content' => [
'from' => [
'name' => 'SparkPost Team',
'email' => "from@$sending_domain",
],
'subject' => 'Mailing With CC and BCC From PHP',
'html' => '<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing with CC and BCC recipients!</p></body></html>',
'text' => 'Congratulations, {{name}}! You just sent your very first mailing with CC and BCC recipients!',
],
'substitution_data' => ['name' => 'YOUR_FIRST_NAME'],
'recipients' => [
[
'address' => [
'name' => 'YOUR_NAME',
'email' => $your_email,
],
],
],
'cc' => [
[
'address' => [
'name' => 'ANOTHER_NAME',
'email' => $your_cc,
],
],
],
'bcc' => [
[
'address' => [
'name' => 'AND_ANOTHER_NAME',
'email' => $your_bcc,
],
],
],
]);
try {
$response = $promise->wait();
echo $response->getStatusCode()."\n";
print_r($response->getBody())."\n";
} catch (\Exception $e) {
echo $e->getCode()."\n";
echo $e->getMessage()."\n";
}