-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsend-mail.php
More file actions
37 lines (30 loc) · 1.17 KB
/
send-mail.php
File metadata and controls
37 lines (30 loc) · 1.17 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
<?php
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapClient;
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Header\UnstructuredHeader;
require __DIR__ . '/../vendor/autoload.php';
/**
* Email Testing API
*
* POST https://sandbox.api.mailtrap.io/api/send/{inbox_id}
*/
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
);
$email = (new MailtrapEmail())
->from(new Address('mailtrap@example.com', 'Mailtrap Test'))
->to(new Address('email@example.com', 'Jon'))
->subject('Hello from Mailtrap!')
->text('Welcome to Mailtrap Sandbox!')
;
$response = $mailtrap->send($email);
// print information from the response
var_dump(ResponseHelper::toArray($response)); // body (array)
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}