summaryrefslogtreecommitdiffstats
path: root/examples/transmissions/create_transmission_with_cc_and_bcc.php
blob: 4c12f815d7c77065dc64640e164e175969f82f59 (plain)
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
<?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());

/**
 * configure options in example-options.json
 */
$sparky = new SparkPost($httpClient, $options);

$promise = $sparky->transmissions->post([
	'content' => [
        'from'=> [
            'name' => 'SparkPost Team',
            'email' => 'from@sparkpostbox.com'
        ],
        'subject'=>'First Mailing From PHP',
        'html'=>'<html><body><h1>Congratulations, {{name}}!</h1><p>You just sent your very first mailing!</p></body></html>',
        'text'=>'Congratulations, {{name}}!! You just sent your very first mailing!'
    ],
    'substitution_data'=> ['name'=>'YOUR_FIRST_NAME'],
    'recipients'=> [
        [ 'address' => 'YOUR_NAME <YOUR_EMAIL>' ]
    ],
    'cc'=> [
        [ 'address' => 'ANOTHER_NAME <ANOTHER_EMAIL>' ]
    ],
    'bcc'=> [
        [ 'address' => 'AND_ANOTHER_NAME <AND_ANOTHER_EMAIL>' ]
    ]
]);

try {
    $response = $promise->wait();
    echo $response->getStatusCode() . "\n";
    print_r($response->getBody());
} catch (Exception $e) {
    echo $e->getCode() . "\n";
    echo $e->getMessage() . "\n";
}
?>