Skip to content

Conversation

@gaalferov
Copy link
Collaborator

@gaalferov gaalferov commented Oct 29, 2025

Motivation

Improve examples

Changes

How to test

composer test

Summary by CodeRabbit

  • Documentation

    • Restructured main README with consolidated "Supported functionality & Examples" section featuring categorized, linked example files.
    • Added comprehensive Examples Index documenting all runnable scripts organized by category (Email API, Sandbox, Contact Management, General API, Framework-specific quick starts).
    • Added framework-specific README sections for Laravel and Symfony integration.
  • New Features

    • Added 20+ example scripts covering batch email sending, template usage, testing workflows, and framework integrations (Laravel/Symfony).
    • New examples demonstrate transactional emails, bulk sending, sandbox testing, and contact management operations.

@coderabbitai
Copy link

coderabbitai bot commented Oct 29, 2025

Walkthrough

This PR adds comprehensive PHP example scripts demonstrating various Mailtrap API workflows (batch/bulk sending, template usage, contact management, testing) across vanilla PHP and framework contexts (Laravel, Symfony). Documentation is restructured to consolidate and index examples by category. Environment variable access is standardized from getenv() to $_ENV[] superglobal across examples. No changes to public API signatures.

Changes

Cohort / File(s) Summary
Documentation Restructuring
README.md, examples/README.md, src/Bridge/Laravel/README.md, src/Bridge/Symfony/README.md
Consolidated "Supported functionality & Examples" section with categorized links to example files; added Examples sections to bridge READMEs with links to framework-specific runnable scripts.
Batch Sending Examples
examples/batch/bulk.php, examples/batch/bulk_template.php, examples/batch/sandbox.php, examples/batch/sandbox_template.php, examples/batch/transactional.php, examples/batch/transactional_template.php
New scripts demonstrating batch email API with standard and template-based sending across bulk, sandbox, and transactional modes; includes recipient lists and per-recipient template variable overrides.
Bulk Sending Examples
examples/bulk/bulk.php, examples/bulk/bulk_template.php
New scripts showing single-call bulk email sending with attachments, embedded media, custom headers, and template-based variants.
Configuration & Core Sending Examples
examples/config/all.php, examples/sending/all.php, examples/sending/minimal.php, examples/sending/template.php
New scripts demonstrating custom HTTP client configuration, minimal email sending, rich HTML emails with embedded/attached resources, and template-based sending.
Contact Management Examples
examples/contact-fields/all.php, examples/contact-lists/all.php
New scripts covering CRUD operations for contact fields and contact lists via MailtrapGeneralClient.
Sandbox Testing Examples
examples/testing/send-mail.php, examples/testing/template.php
New scripts for sandbox mode email sending with standard and template variants.
Environment Variable Migration
examples/contacts/all.php, examples/general/accounts.php, examples/general/billing.php, examples/general/permissions.php, examples/general/users.php, examples/sending/suppressions.php, examples/sending-domains/all.php, examples/templates/all.php, examples/testing/attachments.php, examples/testing/inboxes.php, examples/testing/messages.php, examples/testing/projects.php
Standardized environment variable access from getenv('VAR') to $_ENV['VAR'] superglobal across all affected files.
Framework Examples (Laravel)
examples/laravel/bulk.php, examples/laravel/sandbox.php, examples/laravel/template.php, examples/laravel/transactional.php
New Laravel Artisan console command examples registering commands for transactional, sandbox, template, and bulk mail sending via MailtrapClient.
Framework Examples (Symfony)
examples/symfony/bulk.php, examples/symfony/sandbox.php, examples/symfony/template.php, examples/symfony/transactional.php
New Symfony 7 console command classes (with #[AsCommand] attributes) demonstrating equivalent sending patterns to Laravel examples.
Removed Examples
examples/sending/emails.php, examples/testing/emails.php
Deleted comprehensive multi-scenario example files covering standard, template, bulk, and batch sending workflows; consolidation into categorized, single-purpose scripts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

  • Repetitive patterns: Most example files follow identical structure (env setup → client init → email construction → send → response handling → error handling), reducing unique reasoning per file.
  • File spread & variety: 40+ affected files across multiple domains (batch, bulk, configuration, contacts, testing, frameworks), requiring cross-file verification for consistency.
  • Environment variable migration: Systematic getenv()$_ENV[] changes across 12 files—straightforward but widespread pattern that benefits from spot-checking for correctness.
  • Framework-specific examples: Symfony and Laravel command implementations introduce some heterogeneity in structure and Symfony attributes that warrant closer inspection.
  • Removed files: Two files deleted without direct replacement; verification that functionality is adequately covered by new categorized examples is needed.

Areas requiring extra attention:

  • Verify all new example files reference correct environment variables and API endpoints for their respective scenarios.
  • Confirm Symfony command attributes (e.g., #[AsCommand(name: ...)]) are properly formatted and command names are consistent.
  • Ensure template variable usage and per-recipient overrides in batch examples are correct.
  • Cross-check that removed examples/sending/emails.php and examples/testing/emails.php scenarios are adequately represented in new categorized scripts.
  • Verify documentation links in READMEs point to correct example file paths.

Possibly related PRs

  • Improve README #54: Overlapping changes to README restructuring and examples indexing; both PRs add comprehensive example documentation coverage.

Suggested reviewers

  • yanchuk
  • kovpack
  • IgorDobryn

Poem

🐰 Examples flourish in batches and bundles,
From sandbox to transactional funnels,
Symfony and Laravel now dance side by side,
With $_ENV guiding each API tide,
A rabbit's delight—more docs, less muddle!

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Improve examples' is vague and generic, using a non-descriptive term that doesn't convey meaningful information about the specific changes in the changeset. While it technically relates to the overall scope of the PR (which does improve examples), it lacks clarity about what specifically was improved or reorganized in the examples. Consider revising the title to be more specific and descriptive of the main change, such as 'Reorganize and expand examples with index and framework-specific guides' or 'Add comprehensive examples index and consolidate documentation'. This would better communicate the primary objective to teammates reviewing the commit history.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description mostly follows the required template structure. It includes a Motivation section ('Improve examples'), a Changes section with specific links to key modifications (Examples index, main README, Laravel, and Symfony updates), and a How to test section with the appropriate composer test command. While the template includes optional sections like Images/GIFs and detailed test checkboxes that are not fully populated, the core required information is present and adequately communicates the scope of changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/improve-examples

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gaalferov gaalferov requested a review from yanchuk November 3, 2025 15:19
@gaalferov gaalferov marked this pull request as ready for review November 3, 2025 15:19
@gaalferov gaalferov linked an issue Nov 3, 2025 that may be closed by this pull request
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
README.md (1)

58-58: Standardize environment variable access to $_ENV[].

The README examples use getenv() while all the new example files in this PR use $_ENV[]. This inconsistency may confuse users.

Consider updating all README examples to use $_ENV[] for consistency:

-    apiKey: getenv('MAILTRAP_API_KEY') // your API key here https://mailtrap.io/api-tokens
+    apiKey: $_ENV['MAILTRAP_API_KEY'] // your API key here https://mailtrap.io/api-tokens

Apply the same change to lines 94, 95, 96, and 142.

🧹 Nitpick comments (26)
examples/sending-domains/all.php (1)

11-12: LGTM! Consistent environment variable access pattern.

The switch from getenv() to $_ENV[] is a good modernization. $_ENV is generally preferred for its predictability and performance.

Consider adding defensive checks for missing environment variables in example code to provide better error messages:

+if (!isset($_ENV['MAILTRAP_ACCOUNT_ID'], $_ENV['MAILTRAP_API_KEY'])) {
+    die("Error: Required environment variables MAILTRAP_ACCOUNT_ID and MAILTRAP_API_KEY must be set.\n");
+}
+
 $accountId = (int) $_ENV['MAILTRAP_ACCOUNT_ID'];
 $config = new Config($_ENV['MAILTRAP_API_KEY']);

This helps users understand what went wrong if they forget to set environment variables when running the examples.

Also applies to: 54-54, 71-71, 89-89

examples/general/users.php (1)

9-10: Missing type cast for consistency.

While the environment variable access pattern is correct, Line 9 doesn't cast $accountId to int, unlike similar code in other example files (e.g., examples/general/billing.php Line 9, examples/sending-domains/all.php Line 11).

For consistency across examples, consider:

-$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
+$accountId = (int) $_ENV['MAILTRAP_ACCOUNT_ID'];

This ensures consistent type handling across all examples, though the API may accept both strings and integers.

examples/testing/messages.php (1)

43-43: Consider reducing duplication of messageId retrieval.

The same environment variable MAILTRAP_INBOX_MESSAGE_ID is fetched 10 times throughout the file. While this maintains independence of each example block, it creates duplication.

Consider fetching it once at the top of the file:

$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$inboxId = $_ENV['MAILTRAP_INBOX_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']);
$messageId = $_ENV['MAILTRAP_INBOX_MESSAGE_ID']; // Fetch once here

$sandboxMessages = (new MailtrapSandboxClient($config))->messages($accountId, $inboxId);

// Then use $messageId throughout without re-fetching

This reduces noise while maintaining the example's clarity.

Also applies to: 60-60, 77-77, 94-94, 111-111, 128-128, 145-145, 162-162, 179-179, 196-196

examples/sending/suppressions.php (1)

11-12: Missing type cast for consistency.

Line 11 doesn't cast $accountId to int, which is inconsistent with similar files like examples/general/billing.php and examples/sending-domains/all.php.

For consistency:

-$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
+$accountId = (int) $_ENV['MAILTRAP_ACCOUNT_ID'];
examples/testing/projects.php (2)

9-10: Missing type cast for consistency.

Line 9 doesn't cast $accountId to int, unlike similar examples in other files.

-$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
+$accountId = (int) $_ENV['MAILTRAP_ACCOUNT_ID'];

35-35: Consider reducing duplication of projectId retrieval.

The environment variable MAILTRAP_PROJECT_ID is fetched three times. Consider fetching once at the top for cleaner code.

$accountId = (int) $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']);
$projectId = (int) $_ENV['MAILTRAP_PROJECT_ID']; // Fetch once here

Also applies to: 70-70, 88-88

examples/testing/inboxes.php (2)

10-11: Missing type cast for consistency.

Line 10 doesn't cast $accountId to int, which is inconsistent with the pattern in examples/general/billing.php.

-$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
+$accountId = (int) $_ENV['MAILTRAP_ACCOUNT_ID'];

36-36: Consider reducing duplication of environment variable retrieval.

Both MAILTRAP_PROJECT_ID (Line 36) and MAILTRAP_INBOX_ID (used 8 times) are fetched multiple times. Consider fetching them once at the top of the file.

$accountId = (int) $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']);
$projectId = (int) $_ENV['MAILTRAP_PROJECT_ID'];
$inboxId = (int) $_ENV['MAILTRAP_INBOX_ID'];

Also applies to: 54-54, 71-71, 88-88, 105-105, 122-122, 139-139, 156-156, 173-173

examples/testing/template.php (1)

30-30: Replace placeholder template UUID with clearer documentation.

The hardcoded UUID 'bfa432fd-0000-0000-0000-8493da283a69' (with -0000-0000-0000- segment) appears to be a placeholder that will fail at runtime. Users must replace this with a valid template UUID from their Mailtrap account.

Consider making this more explicit:

-        ->templateUuid('bfa432fd-0000-0000-0000-8493da283a69')
+        ->templateUuid($_ENV['MAILTRAP_TEMPLATE_UUID']) // Get your template UUID from https://mailtrap.io/email-templates

Or add a prominent inline comment:

-        ->templateUuid('bfa432fd-0000-0000-0000-8493da283a69')
+        ->templateUuid('bfa432fd-0000-0000-0000-8493da283a69') // TODO: Replace with your actual template UUID from https://mailtrap.io/email-templates
examples/bulk/bulk_template.php (1)

28-28: Replace placeholder template UUID with environment variable or clear TODO.

The hardcoded UUID contains an obvious placeholder pattern (-0000-0000-0000-) that will fail unless the user happens to have this exact template ID.

Use an environment variable:

-        ->templateUuid('bfa432fd-0000-0000-0000-8493da283a69')
+        ->templateUuid($_ENV['MAILTRAP_TEMPLATE_UUID']) // Get your template UUID from https://mailtrap.io/email-templates
examples/README.md (1)

6-6: Add period after "etc" for proper punctuation.

-* Export or place inside the file your ENV variables (MAILTRAP_API_KEY, MAILTRAP_INBOX_ID, etc)
+* Export or place inside the file your ENV variables (MAILTRAP_API_KEY, MAILTRAP_INBOX_ID, etc.)
examples/templates/all.php (1)

37-37: Consider using environment variables for template IDs.

The hardcoded $templateId = 12345 appears in multiple places with comments to replace it. While the inline comments guide users, using environment variables would make the examples more readily executable.

-    $templateId = 12345; // Replace with a valid template ID
+    $templateId = (int)$_ENV['MAILTRAP_TEMPLATE_ID']; // Your template ID from https://mailtrap.io/email-templates

This would align with the pattern used for other configuration values throughout the examples.

Also applies to: 76-76, 101-101

examples/laravel/transactional.php (1)

1-3: Clarify the intended file location in comments.

The comments indicate this code should be placed in app/routes/console.php, but the file resides at examples/laravel/transactional.php. This may confuse users about whether to copy the code or run the example directly.

Consider updating the comments to clarify:

 <?php
-# app/routes/console.php
-# php artisan send-mail
+# Example Laravel Artisan command for Mailtrap transactional sending
+# To use: Copy this command closure to your app/routes/console.php
+# Then run: php artisan send-mail

Alternatively, if this file is meant to be run directly, update the README to explain the Laravel examples structure.

examples/laravel/bulk.php (1)

20-20: Consider validating environment variable existence.

Direct access to $_ENV['MAILTRAP_API_KEY'] will produce an undefined array key warning in PHP 8+ if the variable is not set. For production-ready examples, consider adding validation or using null coalescing.

-    apiKey: $_ENV['MAILTRAP_API_KEY'], // your API token from here https://mailtrap.io/api-tokens
+    apiKey: $_ENV['MAILTRAP_API_KEY'] ?? throw new \RuntimeException('MAILTRAP_API_KEY not set'), // your API token from here https://mailtrap.io/api-tokens
examples/config/all.php (2)

14-14: Consider validating environment variable existence.

Direct access to $_ENV['MAILTRAP_API_KEY'] will produce an undefined array key warning in PHP 8+ if the variable is not set.

-$apiToken = $_ENV['MAILTRAP_API_KEY'];
+$apiToken = $_ENV['MAILTRAP_API_KEY'] ?? throw new \RuntimeException('MAILTRAP_API_KEY not set');

22-25: Redundant HttpClientBuilder instantiation.

The Config class already stores the $apiToken and automatically creates an HttpClientBuilder via getHttpClientBuilder() if one isn't set. Manually setting a builder here demonstrates the capability but doesn't leverage the existing $apiToken or custom client you just configured.

If the intent is to demonstrate custom builder setup, consider removing this or clarifying that it overrides the previous setHttpClient() call. Otherwise, this line can be removed since Config will create the builder on demand.

-// Set a custom HTTP client builder
-$config->setHttpClientBuilder(
-    new HttpClientBuilder($apiToken)
-);
examples/batch/sandbox.php (1)

20-22: Consider validating environment variable existence.

Direct access to $_ENV['MAILTRAP_API_KEY'] and $_ENV['MAILTRAP_INBOX_ID'] will produce undefined array key warnings in PHP 8+ if these variables are not set.

     $mailtrap = MailtrapClient::initSendingEmails(
-        apiKey: $_ENV['MAILTRAP_API_KEY'], #your API token from here https://mailtrap.io/api-tokens
+        apiKey: $_ENV['MAILTRAP_API_KEY'] ?? throw new \RuntimeException('MAILTRAP_API_KEY not set'), #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
+        inboxId: $_ENV['MAILTRAP_INBOX_ID'] ?? throw new \RuntimeException('MAILTRAP_INBOX_ID not set') # required param for sandbox sending
     );
examples/laravel/sandbox.php (1)

20-22: Consider validating environment variable existence.

Direct access to $_ENV['MAILTRAP_API_KEY'] and $_ENV['MAILTRAP_INBOX_ID'] will produce undefined array key warnings in PHP 8+ if these variables are not set.

     $response = MailtrapClient::initSendingEmails(
-        apiKey:    $_ENV['MAILTRAP_API_KEY'], // your API token from here https://mailtrap.io/api-tokens
+        apiKey:    $_ENV['MAILTRAP_API_KEY'] ?? throw new \RuntimeException('MAILTRAP_API_KEY not set'), // your API token from here https://mailtrap.io/api-tokens
         isSandbox: true,
-        inboxId:   $_ENV['MAILTRAP_INBOX_ID'], // your Inbox ID from here https://mailtrap.io/inboxes
+        inboxId:   $_ENV['MAILTRAP_INBOX_ID'] ?? throw new \RuntimeException('MAILTRAP_INBOX_ID not set'), // your Inbox ID from here https://mailtrap.io/inboxes
     )->send($email);
examples/bulk/bulk.php (2)

19-19: Consider validating environment variable existence.

Direct access to $_ENV['MAILTRAP_API_KEY'] will produce an undefined array key warning in PHP 8+ if the variable is not set.

-        apiKey: $_ENV['MAILTRAP_API_KEY'], #your API token from here https://mailtrap.io/api-tokens
+        apiKey: $_ENV['MAILTRAP_API_KEY'] ?? throw new \RuntimeException('MAILTRAP_API_KEY not set'), #your API token from here https://mailtrap.io/api-tokens

44-44: File existence not validated before attachment.

attachFromPath('README.md') assumes the file exists. If the script is run from a different directory or the file is missing, this will fail.

Consider adding a check:

-        ->attachFromPath('README.md')
+        ->attachFromPath(file_exists('README.md') ? 'README.md' : throw new \RuntimeException('README.md not found'))

Or adjust the path to be relative to the script:

-        ->attachFromPath('README.md')
+        ->attachFromPath(__DIR__ . '/../README.md')
examples/contacts/all.php (1)

14-15: Consider validating environment variable existence.

Direct access to $_ENV['MAILTRAP_ACCOUNT_ID'] and $_ENV['MAILTRAP_API_KEY'] will produce undefined array key warnings in PHP 8+ if these variables are not set.

-$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
-$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
+$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'] ?? throw new \RuntimeException('MAILTRAP_ACCOUNT_ID not set');
+$config = new Config($_ENV['MAILTRAP_API_KEY'] ?? throw new \RuntimeException('MAILTRAP_API_KEY not set')); #your API token from here https://mailtrap.io/api-tokens
examples/batch/bulk.php (1)

24-24: Consider validating environment variable existence.

Direct access to $_ENV['MAILTRAP_API_KEY'] will produce an undefined array key warning in PHP 8+ if the variable is not set.

-        apiKey: $_ENV['MAILTRAP_API_KEY'], // Your API token from https://mailtrap.io/api-tokens
+        apiKey: $_ENV['MAILTRAP_API_KEY'] ?? throw new \RuntimeException('MAILTRAP_API_KEY not set'), // Your API token from https://mailtrap.io/api-tokens
examples/laravel/template.php (1)

44-44: Consider validating environment variable existence.

Direct access to $_ENV['MAILTRAP_API_KEY'] will produce an undefined array key warning in PHP 8+ if the variable is not set.

-        apiKey: $_ENV['MAILTRAP_API_KEY'] // your API token from here https://mailtrap.io/api-tokens
+        apiKey: $_ENV['MAILTRAP_API_KEY'] ?? throw new \RuntimeException('MAILTRAP_API_KEY not set') // your API token from here https://mailtrap.io/api-tokens
examples/contact-fields/all.php (1)

4-7: Remove unused imports.

The imports for CreateContact, CreateContactEvent, ImportContact, UpdateContact, and ContactExportFilter are not used in this file. Removing them will improve clarity and reduce cognitive load.

Apply this diff to remove the unused imports:

 use Mailtrap\Config;
-use Mailtrap\DTO\Request\Contact\CreateContact;
-use Mailtrap\DTO\Request\Contact\CreateContactEvent;
-use Mailtrap\DTO\Request\Contact\ImportContact;
-use Mailtrap\DTO\Request\Contact\UpdateContact;
 use Mailtrap\Helper\ResponseHelper;
 use Mailtrap\MailtrapGeneralClient;
-use Mailtrap\DTO\Request\Contact\ContactExportFilter;

Also applies to: 10-10

examples/contact-lists/all.php (1)

4-7: Remove unused imports.

The imports for CreateContact, CreateContactEvent, ImportContact, UpdateContact, and ContactExportFilter are not used in this file.

Apply this diff to remove the unused imports:

 use Mailtrap\Config;
-use Mailtrap\DTO\Request\Contact\CreateContact;
-use Mailtrap\DTO\Request\Contact\CreateContactEvent;
-use Mailtrap\DTO\Request\Contact\ImportContact;
-use Mailtrap\DTO\Request\Contact\UpdateContact;
 use Mailtrap\Helper\ResponseHelper;
 use Mailtrap\MailtrapGeneralClient;
-use Mailtrap\DTO\Request\Contact\ContactExportFilter;

Also applies to: 10-10

examples/sending/template.php (1)

8-8: Remove unused import.

The UnstructuredHeader import is not used in this example.

Apply this diff:

 use Symfony\Component\Mime\Address;
 use Symfony\Component\Mime\Email;
-use Symfony\Component\Mime\Header\UnstructuredHeader;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5958e00 and 4486fe9.

📒 Files selected for processing (42)
  • README.md (1 hunks)
  • examples/README.md (1 hunks)
  • examples/batch/bulk.php (1 hunks)
  • examples/batch/bulk_template.php (1 hunks)
  • examples/batch/sandbox.php (1 hunks)
  • examples/batch/sandbox_template.php (1 hunks)
  • examples/batch/transactional.php (1 hunks)
  • examples/batch/transactional_template.php (1 hunks)
  • examples/bulk/bulk.php (1 hunks)
  • examples/bulk/bulk_template.php (1 hunks)
  • examples/config/all.php (1 hunks)
  • examples/contact-fields/all.php (1 hunks)
  • examples/contact-lists/all.php (1 hunks)
  • examples/contacts/all.php (2 hunks)
  • examples/general/accounts.php (1 hunks)
  • examples/general/billing.php (1 hunks)
  • examples/general/permissions.php (2 hunks)
  • examples/general/users.php (1 hunks)
  • examples/laravel/bulk.php (1 hunks)
  • examples/laravel/sandbox.php (1 hunks)
  • examples/laravel/template.php (1 hunks)
  • examples/laravel/transactional.php (1 hunks)
  • examples/sending-domains/all.php (4 hunks)
  • examples/sending/all.php (1 hunks)
  • examples/sending/emails.php (0 hunks)
  • examples/sending/minimal.php (1 hunks)
  • examples/sending/suppressions.php (1 hunks)
  • examples/sending/template.php (1 hunks)
  • examples/symfony/bulk.php (1 hunks)
  • examples/symfony/sandbox.php (1 hunks)
  • examples/symfony/template.php (1 hunks)
  • examples/symfony/transactional.php (1 hunks)
  • examples/templates/all.php (1 hunks)
  • examples/testing/attachments.php (3 hunks)
  • examples/testing/emails.php (0 hunks)
  • examples/testing/inboxes.php (10 hunks)
  • examples/testing/messages.php (11 hunks)
  • examples/testing/projects.php (4 hunks)
  • examples/testing/send-mail.php (1 hunks)
  • examples/testing/template.php (1 hunks)
  • src/Bridge/Laravel/README.md (1 hunks)
  • src/Bridge/Symfony/README.md (1 hunks)
💤 Files with no reviewable changes (2)
  • examples/testing/emails.php
  • examples/sending/emails.php
🧰 Additional context used
🧬 Code graph analysis (35)
examples/sending-domains/all.php (1)
src/Config.php (1)
  • Config (16-107)
examples/general/accounts.php (1)
src/Config.php (1)
  • Config (16-107)
examples/batch/sandbox_template.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (3)
  • MailtrapEmail (18-75)
  • templateUuid (20-30)
  • templateVariables (39-46)
examples/batch/bulk_template.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (3)
  • MailtrapEmail (18-75)
  • templateUuid (20-30)
  • templateVariables (39-46)
examples/sending/suppressions.php (1)
src/Config.php (1)
  • Config (16-107)
examples/sending/template.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (3)
  • MailtrapEmail (18-75)
  • templateUuid (20-30)
  • templateVariables (39-46)
examples/bulk/bulk.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (3)
  • MailtrapEmail (18-75)
  • customVariables (67-74)
  • category (48-58)
examples/batch/bulk.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (1)
  • MailtrapEmail (18-75)
examples/symfony/transactional.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (1)
  • MailtrapEmail (18-75)
examples/general/users.php (1)
src/Config.php (1)
  • Config (16-107)
examples/laravel/bulk.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (1)
  • MailtrapEmail (18-75)
examples/contact-lists/all.php (9)
src/Config.php (1)
  • Config (16-107)
src/Api/General/Contact.php (6)
  • Contact (20-408)
  • getAllContactLists (32-37)
  • getContactList (45-50)
  • createContactList (58-66)
  • updateContactList (75-83)
  • deleteContactList (91-96)
src/DTO/Request/Contact/CreateContact.php (1)
  • CreateContact (10-47)
src/DTO/Request/Contact/CreateContactEvent.php (1)
  • CreateContactEvent (12-42)
src/DTO/Request/Contact/ImportContact.php (1)
  • ImportContact (10-58)
src/DTO/Request/Contact/UpdateContact.php (1)
  • UpdateContact (10-69)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapGeneralClient.php (1)
  • MailtrapGeneralClient (17-27)
src/DTO/Request/Contact/ContactExportFilter.php (1)
  • ContactExportFilter (12-49)
examples/laravel/template.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (3)
  • MailtrapEmail (18-75)
  • templateUuid (20-30)
  • templateVariables (39-46)
examples/testing/projects.php (1)
src/Config.php (1)
  • Config (16-107)
examples/sending/all.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (5)
  • MailtrapEmail (18-75)
  • customVariables (67-74)
  • category (48-58)
  • templateUuid (20-30)
  • templateVariables (39-46)
examples/general/billing.php (1)
src/Config.php (1)
  • Config (16-107)
examples/symfony/sandbox.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (1)
  • MailtrapEmail (18-75)
examples/laravel/transactional.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (1)
  • MailtrapEmail (18-75)
examples/sending/minimal.php (2)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
examples/batch/sandbox.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (1)
  • MailtrapEmail (18-75)
examples/testing/template.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (3)
  • MailtrapEmail (18-75)
  • templateUuid (20-30)
  • templateVariables (39-46)
examples/config/all.php (5)
src/Config.php (4)
  • Config (16-107)
  • setHttpClient (67-72)
  • setHttpClientBuilder (60-65)
  • setResponseThrowOnError (101-106)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/HttpClient/HttpClientBuilder.php (1)
  • HttpClientBuilder (21-60)
src/MailtrapSendingClient.php (1)
  • MailtrapSendingClient (14-21)
src/Mime/MailtrapEmail.php (1)
  • MailtrapEmail (18-75)
examples/symfony/bulk.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (1)
  • MailtrapEmail (18-75)
examples/laravel/sandbox.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (1)
  • MailtrapEmail (18-75)
examples/testing/inboxes.php (1)
src/Config.php (1)
  • Config (16-107)
examples/testing/send-mail.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (1)
  • MailtrapEmail (18-75)
examples/symfony/template.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (3)
  • MailtrapEmail (18-75)
  • templateUuid (20-30)
  • templateVariables (39-46)
examples/templates/all.php (1)
src/Config.php (1)
  • Config (16-107)
examples/testing/messages.php (1)
src/Config.php (1)
  • Config (16-107)
examples/bulk/bulk_template.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (3)
  • MailtrapEmail (18-75)
  • templateUuid (20-30)
  • templateVariables (39-46)
examples/general/permissions.php (1)
src/Config.php (1)
  • Config (16-107)
examples/batch/transactional.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (1)
  • MailtrapEmail (18-75)
examples/batch/transactional_template.php (3)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapClient.php (2)
  • MailtrapClient (20-56)
  • initSendingEmails (34-55)
src/Mime/MailtrapEmail.php (3)
  • MailtrapEmail (18-75)
  • templateUuid (20-30)
  • templateVariables (39-46)
examples/contact-fields/all.php (9)
src/Config.php (1)
  • Config (16-107)
src/Api/General/Contact.php (6)
  • Contact (20-408)
  • getAllContactFields (184-189)
  • getContactField (197-202)
  • createContactField (212-220)
  • updateContactField (230-238)
  • deleteContactField (246-251)
src/DTO/Request/Contact/CreateContact.php (1)
  • CreateContact (10-47)
src/DTO/Request/Contact/CreateContactEvent.php (1)
  • CreateContactEvent (12-42)
src/DTO/Request/Contact/ImportContact.php (1)
  • ImportContact (10-58)
src/DTO/Request/Contact/UpdateContact.php (1)
  • UpdateContact (10-69)
src/Helper/ResponseHelper.php (1)
  • ResponseHelper (14-37)
src/MailtrapGeneralClient.php (1)
  • MailtrapGeneralClient (17-27)
src/DTO/Request/Contact/ContactExportFilter.php (1)
  • ContactExportFilter (12-49)
examples/contacts/all.php (1)
src/Config.php (1)
  • Config (16-107)
🪛 LanguageTool
examples/README.md

[style] ~6-~6: In American English, abbreviations like “etc.” require a period.
Context: ...s (MAILTRAP_API_KEY, MAILTRAP_INBOX_ID, etc) * Some examples require a verified sen...

(ETC_PERIOD)

🪛 markdownlint-cli2 (0.18.1)
examples/README.md

6-6: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


16-16: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


43-43: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


51-51: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


54-54: Bare URL used

(MD034, no-bare-urls)


61-61: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


64-64: Bare URL used

(MD034, no-bare-urls)


78-78: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


79-79: Link text should be descriptive

(MD059, descriptive-link-text)

src/Bridge/Laravel/README.md

332-332: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

🔇 Additional comments (15)
examples/testing/messages.php (1)

10-12: LGTM! Environment variable access updated correctly.

The switch to $_ENV[] is consistent with the PR-wide refactoring.

examples/general/billing.php (1)

9-10: LGTM! Correct implementation with proper type casting.

This file correctly casts $accountId to int, which is the pattern other example files should follow.

examples/general/accounts.php (1)

9-9: LGTM! Clean environment variable access.

The change is straightforward and consistent with the PR-wide refactoring.

examples/testing/send-mail.php (1)

17-37: LGTM! Clear and well-structured sandbox example.

The example demonstrates sandbox email sending with:

  • Proper initialization using named arguments
  • Clean email construction
  • Basic error handling

This serves as an excellent starting point for users.

examples/general/permissions.php (1)

13-14: Confirm whether $_ENV usage is intentional and document php.ini requirement if accepted.

The change from getenv() to $_ENV[] is confirmed in the PR. The portability concern is valid: $_ENV requires variables_order to include "E" in php.ini, while getenv() works regardless of configuration and is more reliable across different hosting environments.

However, this entire codebase already uses $_ENV consistently across all example files. Before proceeding:

  • Confirm whether this $_ENV pattern is an intentional architectural decision
  • If intentional, add documentation to README or CONTRIBUTING about the php.ini variables_order requirement
  • If unintentional, consider reverting to getenv() for broader compatibility
examples/laravel/template.php (1)

16-17: Excellent documentation of template constraints.

The comment clearly explains the API validation rules when using templates, helping developers avoid common mistakes.

src/Bridge/Symfony/README.md (1)

196-201: LGTM!

The Examples section provides clear navigation to Symfony-specific runnable scripts and aligns well with the PR's goal to improve examples organization.

examples/batch/transactional.php (1)

1-43: LGTM!

This example cleanly demonstrates batch sending for transactional emails with appropriate error handling and no extraneous imports.

examples/sending/minimal.php (1)

1-33: LGTM!

This minimal example is clean, focused, and demonstrates the essential email sending workflow without unnecessary complexity.

examples/batch/sandbox_template.php (1)

1-64: LGTM!

This example effectively demonstrates batch sending with templates in sandbox mode, including both base template variables and per-recipient overrides. The code is clean and well-structured.

src/Bridge/Laravel/README.md (1)

332-337: No duplicate Examples sections found—dismiss the review comment.

The verification confirms only one ## Examples heading exists at line 332. The original concern about duplication is unfounded; no action is needed.

examples/batch/transactional_template.php (1)

1-65: LGTM!

The example correctly demonstrates batch sending with template-based emails. The structure is clear, uses appropriate error handling, and properly shows per-recipient template variable overrides.

README.md (1)

231-279: LGTM!

The consolidated "Supported functionality & Examples" section provides excellent organization and comprehensive coverage of all API capabilities with clear links to runnable examples.

examples/batch/bulk_template.php (1)

1-66: LGTM!

The bulk template batch sending example is clear and correct. The isBulk: true flag properly differentiates this from the transactional variant, and the self-contained structure makes it easy for users to understand.

examples/sending/all.php (1)

1-114: LGTM!

The file effectively demonstrates two distinct sending patterns: a rich HTML email with attachments and custom headers, and a template-based email. The separate try/catch blocks for each flow make the examples clear and self-contained.

@yanchuk yanchuk merged commit 4bafa37 into main Nov 6, 2025
18 checks passed
@yanchuk yanchuk deleted the feature/improve-examples branch November 6, 2025 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update examples

4 participants