-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsandbox.php
More file actions
41 lines (34 loc) · 1.75 KB
/
sandbox.php
File metadata and controls
41 lines (34 loc) · 1.75 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
<?php
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapClient;
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;
require __DIR__ . '/../vendor/autoload.php';
/**
* Test Email Batch
*
* Batch send email (text, html, text&html, templates).
* Please note that the endpoint will return a 200-level http status, even when sending for individual messages may fail.
* Users of this endpoint should check the success and errors for each message in the response (the results are ordered the same as the original messages - requests).
* Please note that the endpoint accepts up to 500 messages per API call, and up to 50 MB payload size, including attachments.
*/
try {
$mailtrap = MailtrapClient::initSendingEmails(
apiKey: $_ENV['MAILTRAP_API_KEY'], #your API token from here https://mailtrap.io/api-tokens
isSandbox: true, # Sandbox sending (@see https://help.mailtrap.io/article/109-getting-started-with-mailtrap-email-testing)
inboxId: $_ENV['MAILTRAP_INBOX_ID'] # required param for sandbox sending
);
$baseEmail = (new MailtrapEmail())
->from(new Address('example@YOUR-DOMAIN-HERE.com', 'Mailtrap Test')) // Use your domain installed in Mailtrap
->subject('Batch Email Subject')
->text('Batch email text')
->html('<p>Batch email text</p>');
$recipientEmails = [
(new MailtrapEmail())->to(new Address('recipient1@example.com', 'Recipient 1')),
(new MailtrapEmail())->to(new Address('recipient2@example.com', 'Recipient 2')),
];
$response = $mailtrap->batchSend($recipientEmails, $baseEmail);
var_dump(ResponseHelper::toArray($response)); // Output response body as array
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}