Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ Email API:
- Batch send with Template (Transactional) – [`batch/transactional_template.php`](examples/batch/transactional_template.php)
- Batch send with Template (Bulk) – [`batch/bulk_template.php`](examples/batch/bulk_template.php)
- Sending domain management CRUD – [`sending-domains/all.php`](examples/sending-domains/all.php)
- Suppressions (find & delete) – [`sending/suppressions.php`](examples/sending/suppressions.php)
- Email Logs (list & get by message ID) – [`sending/email-logs.php`](examples/sending/email-logs.php)

Email Sandbox (Testing):
- Send an email (Sandbox) – [`testing/send-mail.php`](examples/testing/send-mail.php)
Expand All @@ -260,7 +262,6 @@ Contact management:

General API:
- Templates CRUD – [`templates/all.php`](examples/templates/all.php)
- Suppressions (find & delete) – [`sending/suppressions.php`](examples/sending/suppressions.php)
- Billing info – [`general/billing.php`](examples/general/billing.php)
- Accounts info – [`general/accounts.php`](examples/general/accounts.php)
- Permissions listing – [`general/permissions.php`](examples/general/permissions.php)
Expand Down
2 changes: 1 addition & 1 deletion examples/batch/bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

/**
* Email Batch Sending API (Bulk)
Expand Down
2 changes: 1 addition & 1 deletion examples/batch/bulk_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

/**
* Email Batch Sending WITH TEMPLATE (Bulk)
Expand Down
2 changes: 1 addition & 1 deletion examples/batch/sandbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

/**
* Test Email Batch
Expand Down
2 changes: 1 addition & 1 deletion examples/batch/sandbox_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

/**
* Test Email Batch WITH TEMPLATE
Expand Down
2 changes: 1 addition & 1 deletion examples/batch/transactional.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

/**
* Email Batch Sending API (Transactional)
Expand Down
2 changes: 1 addition & 1 deletion examples/batch/transactional_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

/**
* Email Batch Sending WITH TEMPLATE (Transactional)
Expand Down
2 changes: 1 addition & 1 deletion examples/bulk/bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Header\UnstructuredHeader;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

/**
* Email Bulk Sending API
Expand Down
2 changes: 1 addition & 1 deletion examples/bulk/bulk_template.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

/**
* Email Bulk Sending WITH TEMPLATE
Expand Down
2 changes: 1 addition & 1 deletion examples/config/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\HttpClient\Psr18Client;
use Symfony\Component\Mime\Address;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';


$apiToken = $_ENV['MAILTRAP_API_KEY'];
Expand Down
2 changes: 1 addition & 1 deletion examples/contact-fields/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Mailtrap\MailtrapGeneralClient;
use Mailtrap\DTO\Request\Contact\ContactExportFilter;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
Expand Down
2 changes: 1 addition & 1 deletion examples/contact-lists/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Mailtrap\MailtrapGeneralClient;
use Mailtrap\DTO\Request\Contact\ContactExportFilter;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
Expand Down
2 changes: 1 addition & 1 deletion examples/contacts/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Mailtrap\MailtrapGeneralClient;
use Mailtrap\DTO\Request\Contact\ContactExportFilter;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
Expand Down
2 changes: 1 addition & 1 deletion examples/general/accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapGeneralClient;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
$generalAccounts = (new MailtrapGeneralClient($config))->accounts();
Expand Down
2 changes: 1 addition & 1 deletion examples/general/billing.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapGeneralClient;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$accountId = (int) $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
Expand Down
2 changes: 1 addition & 1 deletion examples/general/permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapGeneralClient;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
Expand Down
2 changes: 1 addition & 1 deletion examples/general/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapGeneralClient;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
Expand Down
2 changes: 1 addition & 1 deletion examples/sending/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Header\UnstructuredHeader;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';


/**
Expand Down
81 changes: 81 additions & 0 deletions examples/sending/email-logs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

declare(strict_types=1);

use Mailtrap\Config;
use Mailtrap\DTO\Request\EmailLogs\EmailLogsListFilters;
use Mailtrap\DTO\Request\EmailLogs\FilterCriterion;
use Mailtrap\DTO\Request\EmailLogs\EmailLogsFilterOperator;
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapSendingClient;

require __DIR__ . '/../../vendor/autoload.php';

$accountId = (int) $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']);
$emailLogs = (new MailtrapSendingClient($config))->emailLogs($accountId);

/**
* List email logs (paginated).
*
* GET https://mailtrap.io/api/accounts/{account_id}/email_logs
*/
try {
// Get first page (no filters)
$response = $emailLogs->getList();
$data = ResponseHelper::toArray($response);

echo "Total count: " . $data['total_count'] . PHP_EOL;
foreach ($data['messages'] as $msg) {
echo " - " . $msg['message_id'] . " | " . $msg['status'] . " | " . ($msg['subject'] ?? '') . PHP_EOL;
}

// Optional: filter by date range (last 2 days), recipient, categories – using the filters model
$sentBefore = (new DateTimeImmutable('now', new DateTimeZone('UTC')))->format(DateTimeInterface::ATOM);
$sentAfter = (new DateTimeImmutable('-2 days', new DateTimeZone('UTC')))->format(DateTimeInterface::ATOM);
$filters = EmailLogsListFilters::create(
$sentAfter,
$sentBefore,
[
'subject' => FilterCriterion::withoutValue(EmailLogsFilterOperator::NOT_EMPTY),
'to' => FilterCriterion::withValue(EmailLogsFilterOperator::CI_EQUAL, 'recipient@example.com'),
'category' => FilterCriterion::withValue(EmailLogsFilterOperator::EQUAL, ['Welcome Email', 'Order Confirmation']),
]
);
$response = $emailLogs->getList($filters);
$data = ResponseHelper::toArray($response);

// Next page (use next_page_cursor from previous response)
$cursor = $data['next_page_cursor'] ?? null;
if ($cursor !== null) {
$response = $emailLogs->getList($filters, $cursor);
$data = ResponseHelper::toArray($response);
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}

/**
* Get a single email log message by ID.
*
* GET https://mailtrap.io/api/accounts/{account_id}/email_logs/{sending_message_id}
*/
try {
$listResponse = $emailLogs->getList();
$listData = ResponseHelper::toArray($listResponse);
$messageId = isset($listData['messages'][0]) ? $listData['messages'][0]['message_id'] : null;

if ($messageId !== null) {
$response = $emailLogs->getMessage($messageId);
$message = ResponseHelper::toArray($response);

echo "Message: " . $message['message_id'] . PHP_EOL;
echo "Status: " . $message['status'] . PHP_EOL;
echo "Subject: " . ($message['subject'] ?? '') . PHP_EOL;
echo "Events: " . count($message['events'] ?? []) . PHP_EOL;
} else {
echo "No messages in the list." . PHP_EOL;
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), PHP_EOL;
}
2 changes: 1 addition & 1 deletion examples/sending/minimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mailtrap\Mime\MailtrapEmail;
use Symfony\Component\Mime\Address;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';


/**
Expand Down
2 changes: 1 addition & 1 deletion examples/sending/suppressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapSendingClient;

require __DIR__ . '/../vendor/autoload.php';
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
Expand Down
2 changes: 1 addition & 1 deletion examples/sending/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Header\UnstructuredHeader;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';


/**
Expand Down
2 changes: 1 addition & 1 deletion examples/templates/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapGeneralClient;

require __DIR__ . '/../vendor/autoload.php';
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
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapSandboxClient;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$inboxId = $_ENV['MAILTRAP_INBOX_ID'];
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/inboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapSandboxClient;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapSandboxClient;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

// your API token from here https://mailtrap.io/api-tokens
$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapSandboxClient;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';

$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/send-mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Header\UnstructuredHeader;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';


/**
Expand Down
2 changes: 1 addition & 1 deletion examples/testing/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Header\UnstructuredHeader;

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../../vendor/autoload.php';


/**
Expand Down
Loading
Loading