- How do I integrate this Mailjet PHP wrapper with Laravel?
- Bind Mailjet credentials in `config/services.php` and register the client in Laravel’s service container. Use dependency injection to instantiate the client in controllers or services. The wrapper’s PSR-18 compliance ensures compatibility with Laravel’s built-in HTTP clients like Guzzle or Symfony HttpClient.
- Does this package support Laravel’s queue system for async email sending?
- The wrapper itself is synchronous, but you can wrap Mailjet calls in a Laravel job and dispatch them to a queue. Use Laravel’s queue workers to process emails asynchronously, ensuring non-blocking email delivery.
- What Laravel versions are compatible with this package?
- This package requires PHP 8.1+, which aligns with Laravel 9+. If you’re using an older Laravel version, you’ll need to upgrade or use a different Mailjet package that supports PHP 7.x.
- How do I handle API errors or rate limits in Laravel?
- The wrapper returns a `Response` object, but for Laravel-specific error handling, create custom exceptions (e.g., `MailjetException`) and log them using Laravel’s logging system. For rate limits, implement retry logic with Laravel’s retry helper or a custom decorator.
- Can I use this wrapper with a custom HTTP client like Symfony HttpClient?
- Yes, the wrapper supports ‘Bring Your Own Client’ (PSR-18 compliant). Explicitly require `symfony/http-client` in your `composer.json` and configure the wrapper to use it instead of the auto-installed Guzzle.
- How do I mock the Mailjet client for testing in Laravel?
- Use the wrapper’s `disable API call` feature by setting `$CALL = false` in the client configuration. This allows you to test your Laravel logic without hitting Mailjet’s API, simplifying unit and integration tests.
- Is there a Laravel-specific package for Mailjet, or should I use this wrapper?
- If Mailjet offers an official Laravel package, prefer it for tighter integration. This wrapper is ideal if you need full control over the Mailjet API or require features like SMS support (v4) not covered by Laravel-specific packages.
- How do I manage API credentials securely in Laravel?
- Store credentials in Laravel’s `.env` file (e.g., `MAILJET_API_KEY`, `MAILJET_API_SECRET`) and reference them in `config/services.php`. For production, consider using a secrets manager like AWS Secrets Manager or Laravel Forge for enhanced security.
- Does this wrapper support batching or parallel requests for high-volume emails?
- The wrapper supports batching via its resource methods, but parallel requests require custom logic. Use Laravel’s queue system or a library like `spatie/async` to process emails concurrently while respecting Mailjet’s rate limits.
- What’s the best way to log Mailjet API responses or errors in Laravel?
- Extend the wrapper’s `Response` object to log data using Laravel’s logging system (e.g., `Log::debug()`). For centralized monitoring, integrate with tools like Sentry or Laravel’s built-in error logging to track API failures and performance.