- How do I install the Mailcoach SDK in a Laravel project?
- Use Composer to install the package with `composer require spatie/mailcoach-sdk-php`. Then configure your API key and endpoint in `config/services.php` or `.env` (e.g., `MAILCOACH_API_KEY=your_key`). Register the SDK as a singleton in `AppServiceProvider` for dependency injection.
- Does this SDK support both self-hosted Mailcoach and Mailcoach Cloud?
- Yes, the SDK works with both self-hosted Mailcoach (v6+) and Mailcoach Cloud. Just specify the correct API endpoint in your configuration. The same codebase handles both environments seamlessly.
- Can I use this SDK to send transactional emails alongside marketing campaigns?
- Yes, the SDK supports transactional emails (added in v1.9.0+). You can integrate it with Laravel’s Mail facade for hybrid workflows, though Mailcoach’s primary focus remains marketing campaigns like newsletters.
- How does pagination work with the SDK, and can I customize the page size?
- The SDK uses Mailcoach’s default pagination (1000 items/page) but provides a `next()` method to iterate through results. You can’t directly customize the page size via the SDK, but Mailcoach’s API allows adjusting this on the server side if needed.
- Is there built-in support for Laravel’s queue system to handle async operations?
- Yes, offload async operations like sending campaigns to Laravel’s queue by wrapping SDK calls in queueable jobs. This improves performance for high-volume tasks and avoids timeouts.
- How do I handle API rate limits in Laravel with this SDK?
- The SDK includes rate-limit exceptions (v1.9.1+). Pair it with `spatie/laravel-queueable-rate-limiting` to implement retries for throttled requests. Monitor Mailcoach’s API limits and adjust Laravel’s queue workers accordingly.
- Can I sync Mailcoach subscribers with Laravel Eloquent models (e.g., Users)?
- Yes, use Eloquent observers or Laravel’s Model events to sync data. For example, trigger a Mailcoach subscriber update when a User model is created or updated. The SDK’s resource objects (e.g., `Subscriber`) map cleanly to Eloquent attributes.
- What Laravel versions and PHP versions are supported by this SDK?
- The SDK requires PHP 8.0+ and is compatible with Laravel 8+. Check the [GitHub repo](https://github.com/spatie/mailcoach-sdk-php) for the latest version’s specific requirements, as dependencies like Guzzle may have version constraints.
- Are there alternatives to this SDK for Laravel Mailcoach integrations?
- For basic API interactions, you could use Guzzle directly or Mailcoach’s official API docs. However, this SDK provides Laravel-specific conveniences like pagination helpers, event-driven automations, and seamless integration with Laravel’s service container, saving development time.
- How do I test Mailcoach campaigns locally before sending to subscribers?
- Use the `sendTest()` method on a campaign object to send test emails to specific addresses (e.g., `$campaign->sendTest('test@example.com')`). For Laravel-specific testing, mock the SDK’s HTTP client or use Mailcoach’s sandbox environment if available.