-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathall.php
More file actions
108 lines (90 loc) · 2.95 KB
/
all.php
File metadata and controls
108 lines (90 loc) · 2.95 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
declare(strict_types=1);
use Mailtrap\Config;
use Mailtrap\DTO\Request\EmailTemplate;
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapGeneralClient;
require __DIR__ . '/../vendor/autoload.php';
$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); // Your API token from https://mailtrap.io/api-tokens
$emailTemplates = (new MailtrapGeneralClient($config))->emailTemplates($accountId);
/**
* Get all Email Templates.
*
* GET https://mailtrap.io/api/accounts/{account_id}/email_templates
*/
try {
$response = $emailTemplates->getAllEmailTemplates();
// Print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
/**
* Get Email Template by ID.
*
* GET https://mailtrap.io/api/accounts/{account_id}/email_templates/{id}
*/
try {
$templateId = 12345; // Replace with a valid template ID
$response = $emailTemplates->getEmailTemplate($templateId);
// Print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
/**
* Create a new Email Template.
*
* POST https://mailtrap.io/api/accounts/{account_id}/email_templates
*/
try {
$response = $emailTemplates->createEmailTemplate(
EmailTemplate::init(
'Welcome Email', // Name
'Welcome to our service!', // Subject
'Transactional', // Category
'Welcome to our service!', // Text Body
'<div>Welcome to our service!</div>' // HTML Body
)
);
// Print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
/**
* Update an Email Template by ID.
*
* PATCH https://mailtrap.io/api/accounts/{account_id}/email_templates/{email_template_id}
*/
try {
$templateId = 12345; // Replace with a valid template ID
$response = $emailTemplates->updateEmailTemplate(
$templateId,
EmailTemplate::init(
'Updated Welcome Email', // Name
'Updated Subject', // Subject
'Transactional', // Category
'Updated Text Body', // Text Body
'<div>Updated HTML Body</div>', // HTML Body
)
);
// Print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
/**
* Delete an Email Template by ID.
*
* DELETE https://mailtrap.io/api/accounts/{account_id}/email_templates/{email_template_id}
*/
try {
$templateId = 12345; // Replace with a valid template ID
$response = $emailTemplates->deleteEmailTemplate($templateId);
// Print the response status code
var_dump($response->getStatusCode());
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}