-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoracle-bronto-send-email.php
98 lines (91 loc) · 3.06 KB
/
oracle-bronto-send-email.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
date_default_timezone_set('Europe/London');
$client = new SoapClient('http://api.bronto.com/v4?wsdl', array(
'trace' => 1,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS
));
try {
// Add API token here
$token = "YOUR_GOES_HERE";
print "logging in\n";
// The session will end if there is no transaction for 20 minutes.
$sessionId = $client->login(array(
'apiToken' => $token
))->return;
$session_header = new SoapHeader("http://api.bronto.com/v4", 'sessionHeader', array(
'sessionId' => $sessionId
));
$client->__setSoapHeaders(array(
$session_header
));
// Make delivery start timestamp
// set up a filter to read contacts and match on either of two email addresses
$filter = array(
'type' => 'OR',
'email' => array(
array(
'operator' => 'EqualTo',
'value' => '[email protected]'
)
)
);
print "reading contacts with equalto filter\n";
$contacts = $client->readContacts(array(
'pageNumber' => 1,
'includeLists' => false,
'filter' => $filter
))->return;
// print matching contact email addresses
foreach ($contacts as $contact) {
print_r("Email id==>" . $contact->id . "\n");
}
$now = date('c');
$deliveryRecipientObject = array(
'type' => 'contact',
'id' => 'CONTACT_EMAIL_ID'
);
// Create an array of delivery parameters including the content
// which will be displayed by the loop tags added in the example
// message.
$delivery = array();
$delivery['start'] = $now;
$delivery['messageId'] = 'TEMPLATE_MESSAGE_ID';
$delivery['fromName'] = 'API Robot';
$delivery['fromEmail'] = '[email protected]';
$delivery['recipients'] = array(
$deliveryRecipientObject
);
// Notice below that when you reference the name of the loop tag via the API,
// be sure to leave off the "%%# _#%%" portion of the tag. You will build
// an array using individual API message tags which are named
// as follows: basename_number. For example, name => item_1, rather
// than name => %%#item_#%%.
$delivery['fields'][] = array(
'name' => 'subject',
'type' => 'html',
'content' => 'A cool subject'
);
$delivery['fields'][] = array(
'name' => 'first_name',
'type' => 'html',
'content' => '<strong>Panayiotis</strong>'
);
$deliveries[] = $delivery;
$parameters = array(
'deliveries' => $deliveries
);
print_r($parameters);
$res = $client->addDeliveries($parameters)->return;
print_r($res);
if ($res->errors) {
print "There was a problem scheduling your delivery:\n";
print $res->results[$res->errors[0]]->errorString . "\n";
} else {
print "Delivery has been scheduled. Id: " . $res->results[0]->id . "\n";
}
}
catch (Exception $e) {
print "uncaught exception\n";
print_r($e);
}
?>