-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
91 lines (74 loc) · 2.21 KB
/
test.php
File metadata and controls
91 lines (74 loc) · 2.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
87
88
89
90
91
<?php
declare(strict_types=1);
require __DIR__ . '/packages/default/send-email/vendor/autoload.php';
// Constants
const OK = 1;
const HTTP_OK = 200;
const ERROR = -1;
$data = json_encode([
'name' => 'Yehor',
]);
if (!$data) {
exit('Please supply data argument.');
}
$args = [
'smtp_server' => 'smtp.mailgun.org',
'smtp_port' => 587,
'smtp_username' => '',
'smtp_password' => '',
'subject' => 'PDF file test',
'sender_email' => 'author@example.com',
'sender_name' => 'Test Sender',
'recipient_email' => 'egorsmkv@gmail.com',
'recipient_name' => 'Yehor Smoliakov',
'template' => 'hello',
'variables' => base64_encode($data),
'attachment_urls' => [
[
'filename' => 'test_1.pdf',
'url' => 'https://raw.githubusercontent.com/ElefantOne/do-functions-php-send-email/refs/heads/main/packages/default/send-email/test.pdf',
'type' => 'application/pdf',
],
[
'filename' => 'test_2.pdf',
'url' => 'https://raw.githubusercontent.com/ElefantOne/do-functions-php-send-email/refs/heads/main/packages/default/send-email/test.pdf',
'type' => 'application/pdf',
],
],
];
$client = new \GuzzleHttp\Client();
$url = 'https://faas-fra1-afec6ce7.doserverless.co/api/v1/web/fn-d162e87e-b749-4ae7-ac9c-1a295057435a/default/send-email';
$response = $client->post($url, [
// Config
'connect_timeout' => 20,
'read_timeout' => 20,
'timeout' => 30,
// The data
'json' => $args,
]);
$responseBody = $response->getBody()->getContents();
$responseCode = $response->getStatusCode();
if (HTTP_OK !== $responseCode) {
echo "Something went wrong!\n";
exit(1);
}
echo "HTTP call was successful!\n";
/**
* @var array $parsedData
*/
$parsedData = json_decode($responseBody, true);
/**
* @var array $response
*/
$response = $parsedData['response'];
switch ($response['status']) {
case OK:
echo "Notification sent successfully!\n";
break;
case ERROR:
echo "Notification failed to send! Use parsedData variable to find out more.\n";
break;
default:
echo "Something went wrong! Use parsedData variable to find out more.\n";
break;
}