-
Notifications
You must be signed in to change notification settings - Fork 10
/
sendTransactionalEmails.php
51 lines (46 loc) · 1.95 KB
/
sendTransactionalEmails.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
<?php
/*
* API Docs
* https://elasticemail.com/developers/api-documentation/rest-api#operation/emailsTransactionalPost
*
* Snippets
* https://github.com/ElasticEmail/elasticemail-php
*/
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: apikey
define('MY_APIKEY', 'YOUR_API_KEY');
$config = ElasticEmail\Configuration::getDefaultConfiguration()->setApiKey('X-ElasticEmail-ApiKey', MY_APIKEY);
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = ElasticEmail\Configuration::getDefaultConfiguration()->setApiKeyPrefix('X-ElasticEmail-ApiKey', 'Bearer');
$apiInstance = new ElasticEmail\Api\EmailsApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$email_message_data = new \ElasticEmail\Model\EmailTransactionalMessageData([
"recipients" => new \ElasticEmail\Model\TransactionalRecipient([
"to" => ["email@domain.com, email2@domain.com, email3@domain.com"],
"cc" => ["email4@domain.com, email5@domain.com"],
"bcc" => ["email6@domain.com"]
]),
"content" => new \ElasticEmail\Model\EmailContent([
"body" => [new \ElasticEmail\Model\BodyPart([
"content_type" => "HTML",
"content" => "My test email content"
])
],
"from" => "mail@contact.com",
"subject" => "My Subject",
"reply_to" => "mail@contact.com",
]),
"options" => new \ElasticEmail\Model\Options([
"channel_name" => "My Channel"
])
]); // \ElasticEmail\Model\EmailMessageData | Email data
try {
$response = $apiInstance->emailsTransactionalPost($email_message_data);
print('<pre>' . print_r( $response, true) . '</pre>');
} catch (Exception $e) {
echo 'Exception when calling EmailsApi->emailsTransactionalPost: ', $e->getMessage(), PHP_EOL;
}