-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathBulkComplexExample.php
More file actions
86 lines (71 loc) · 3.21 KB
/
BulkComplexExample.php
File metadata and controls
86 lines (71 loc) · 3.21 KB
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
<?php
include_once(__DIR__ . "../../includes.php");
use Socketlabs\Message\BulkMessage;
use Socketlabs\Message\BulkRecipient;
use Socketlabs\Message\EmailAddress;
use Socketlabs\Message\CustomHeader;
use Socketlabs\Message\Attachment;
use Socketlabs\Message\Metadata;
use Socketlabs\SocketLabsClient;
$client = new SocketLabsClient(exampleConfig::serverId(), exampleConfig::password());
//Build the message
$message = new BulkMessage();
//Add some global merge-data (These will be applied to all Recipients unless specifically overridden by Recipient level merge-data)
$message->addGlobalMergeData("Motto", "When hitting the Inbox matters!");
$message->addGlobalMergeData("Birthday", "Unknown");
$message->addGlobalMergeData("Age", "an unknown number of");
$message->addGlobalMergeData("UpSell", "BTW: You are eligible for discount pricing when you upgrade your service!");
//Add recipients with merge data
$recipient1 = new BulkRecipient("recipient1@example.com");
$recipient1->addMergeData("Birthday", "08/05/1991");
$recipient1->addMergeData("Age", "27");
$message->addToAddress($recipient1);
$recipient2 = new BulkRecipient("recipient2@example.com");
$recipient2->addMergeData("Birthday", "04/12/1984");
$recipient2->addMergeData("Age", "34");
$recipient2->addMergeData("UpSell", ""); // This will override the Global Merge-Data for this specific Recipient
$message->addToAddress($recipient2);
$recipient3 = new BulkRecipient("recipient3@example.com", "Recipient 3"); // The merge-data for this Recipient will be populated with Global Merge-Data
$message->addToAddress($recipient3);
//Set other properties as needed
$message->subject = "Complex BulkSend Example";
$message->from = new EmailAddress("from@example.com", "FromMe");
$message->replyTo = new EmailAddress("replyto@example.com");
//Apply Custom Headers to the message
$message->customHeaders[] = new CustomHeader("testMessageHeader", "I am a message header");
//Apply Metadata to the message
$message->metadata[] = new Metadata("x-mycustommetadata", "I am custom metadata");
//Add tag to message
$message->tags[] = "Basic-Complex-Example-PHP";
//Build the Content (Note the %% symbols used to denote the data to be merged)
$message->htmlBody = "<html>" .
"<head><title>Complex</title></head>" .
"<body>" .
"<h1>Merged Data</h1>" .
"<p>" .
"Motto = <b>%%Motto%%</b> </br>" .
"Birthday = <b>%%Birthday%%</b> </br>" .
"Age = <b>%%Age%%</b> </br>" .
"UpSell = <b>%%UpSell%%</b> </br>" .
"</p>" .
"</br>" .
"<h1>Example of Merge Usage</h1>" .
"<p>" .
"Our company motto is '<b>%%Motto%%</b>'. </br>" .
"Your birthday is <b>%%Birthday%%</b> and you are <b>%%Age%%</b> years old. </br>" .
"</br>" .
"<b>%%UpSell%%<b>" .
"</p>" .
"</body>" .
"</html>";
$message->plainTextBody = "Global Merge Data" .
"CompanyMotto = %%Motto%%" .
" " .
"Per Recipient Merge Data" .
" EyeColor = %%EyeColor%%" .
" HairColor = %%HairColor%%";
//Add an attachment (with a Custom Header)
$att = Attachment::createFromPath(__DIR__ . "/../Img/Bus.png", "Bus.png", "IMAGE/PNG", "Bus");
$att->customHeaders = array("Attachment-Header" => "I Am A Bus");
$message->attachments[] = $att;
$response = $client->send($message);