-
Notifications
You must be signed in to change notification settings - Fork 10
Improve examples #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve examples #56
Conversation
WalkthroughThis 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 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes
Areas requiring extra attention:
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this 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-tokensApply 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.$_ENVis 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
$accountIdtoint, unlike similar code in other example files (e.g.,examples/general/billing.phpLine 9,examples/sending-domains/all.phpLine 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_IDis 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-fetchingThis 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
$accountIdtoint, which is inconsistent with similar files likeexamples/general/billing.phpandexamples/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
$accountIdtoint, 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_IDis 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 hereAlso applies to: 70-70, 88-88
examples/testing/inboxes.php (2)
10-11: Missing type cast for consistency.Line 10 doesn't cast
$accountIdtoint, which is inconsistent with the pattern inexamples/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) andMAILTRAP_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-templatesOr 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-templatesexamples/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-templatesexamples/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 = 12345appears 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-templatesThis 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 atexamples/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-mailAlternatively, 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-tokensexamples/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
Configclass already stores the$apiTokenand automatically creates anHttpClientBuilderviagetHttpClientBuilder()if one isn't set. Manually setting a builder here demonstrates the capability but doesn't leverage the existing$apiTokenor 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 sinceConfigwill 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-tokensexamples/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-tokensexamples/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-tokensexamples/contact-fields/all.php (1)
4-7: Remove unused imports.The imports for
CreateContact,CreateContactEvent,ImportContact,UpdateContact, andContactExportFilterare 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, andContactExportFilterare 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
UnstructuredHeaderimport 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
📒 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
$accountIdtoint, 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$_ENVusage 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:$_ENVrequiresvariables_orderto include "E" in php.ini, whilegetenv()works regardless of configuration and is more reliable across different hosting environments.However, this entire codebase already uses
$_ENVconsistently across all example files. Before proceeding:
- Confirm whether this
$_ENVpattern is an intentional architectural decision- If intentional, add documentation to README or CONTRIBUTING about the php.ini
variables_orderrequirement- If unintentional, consider reverting to
getenv()for broader compatibilityexamples/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
## Examplesheading 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: trueflag 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.
Motivation
Improve examples
Changes
How to test
composer testSummary by CodeRabbit
Documentation
New Features