-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathBasicComplexExample.php
More file actions
62 lines (50 loc) · 2.57 KB
/
BasicComplexExample.php
File metadata and controls
62 lines (50 loc) · 2.57 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
<?php
include_once(__DIR__ . "../../includes.php");
use Socketlabs\SocketLabsClient;
use Socketlabs\Message\EmailAddress;
use Socketlabs\Message\CustomHeader;
use Socketlabs\Message\Attachment;
use Socketlabs\Message\Metadata;
use Socketlabs\Message\BasicMessage;
$client = new SocketLabsClient(exampleConfig::serverId(), exampleConfig::password());
// $client->proxyUrl = exampleConfig::proxy(); //Uncomment to configure a proxy
// $client->endpoint = exampleConfig::endpoint() //Uncomment to configure a different endpoint address
//Build the message
$message = new BasicMessage();
$message->subject = "Sending Basic Complex Example";
//Add different types of parties to the message
$message->from = new EmailAddress("from@example.com", "from");
$message->to[] = new EmailAddress("recipient@example.com", "recipient name");
$message->cc[] = new EmailAddress("cc@example.com", "cc name");
$message->bcc[] = new EmailAddress("bcc@example.com", "bcc name");
//Set reply to
$message->replyTo = new EmailAddress("replyto@example.com", "Reply Address");
//set html and text body parts
$message->htmlBody = "<body><p><strong>Lorem Ipsum</strong></p><br /><img src=\"cid:Bus\" /></body>";
$message->plainTextBody = "Lorem Ipsum";
$message->charset = "utf-8";
//Tag message with mailing and message ids.
//See https://support.socketlabs.com/index.php/Knowledgebase/Article/View/48/2/using-mailingcampaign-ids-and-message-ids-with-socketlabs-email-on-demand
$message->mailingId = "My Mailing Id"; //Identifier for groups of messages such as campaigns, jobs, or batches of messages.
$message->messageId = "My Message Id"; //Typically used to identify a specific message or a recipient of a message.
//Add custom headers to the message
$message->customHeaders = array(
"My-Header" => "1...2...3...",
"Example-Type" => "BasicWithCustomHeaders",
);
//Apply Metadata to the message
//There are several ways to add metadata to the message
$message->metadata = array(
"x-my-metadata-1" => "I am custom metadata example #1"
);
//OR
$message->metadata[] = new Metadata("x-my-metadata-2", "I am custom metadata example #2");
//OR
$message->addMetadata("x-my-metadata-3", "I am custom metadata example #3");
//Add tag to message
$message->tags[] = "Basic-Complex-Example-PHP";
//Add an attachment. specify the cid as 'Bus' so it can be embedded
$attachment = Attachment::createFromPath(__DIR__ . "/../Img/Bus.png", "Bus.png", "IMAGE/PNG", "Bus");
$attachment->customHeaders[] = new CustomHeader("MyAttachmentHeader", "I am an attachment header");
$message->attachments[] = $attachment;
$response = $client->send($message);