- How do I integrate Spatie Mailcoach with Craft CMS 5 for transactional emails like password resets?
- Install via Composer with `composer require spatie/craft-mailcoach`, then run `./craft plugin/install mailcoach`. Configure your Mailcoach API key in `config/general.php` under the `mailer` component and set it as the default mailer in Craft’s Control Panel under *Settings > System > Mail*. Craft will now route emails through Mailcoach.
- Does this package support Craft CMS 4.x or older PHP versions?
- No, this package strictly requires **Craft CMS 5.0+** and **PHP 8.2+**. If you’re on Craft 4.x or PHP 8.1, you’ll need to upgrade first. Check the [Craft CMS docs](https://craftcms.com/docs) for migration guidance.
- Can I use this alongside other mailers like SparkPost or SendGrid?
- Yes, the adapter follows Craft’s mailer interface, so you can configure it as a fallback or primary mailer. Use Craft’s *Settings > System > Mail* to switch between providers dynamically. For redundancy, set a secondary mailer in your `config/general.php` under the `mailer` component.
- How do I handle Mailcoach API failures or rate limits in production?
- The package relies on Mailcoach’s API, so monitor their [status page](https://mailcoach.app/status) for outages. For rate limits, implement retry logic in your Craft templates or controllers using `Yii::$app->mailer->compose()` with error handling. Log failures via Craft’s `craft.log` for debugging.
- Is there a way to test email delivery before going live?
- Yes, use Craft’s CLI to send test emails: `./craft send-test-email`. Verify delivery by checking your inbox and inspecting headers for Mailcoach-specific tags. For automated testing, mock the mailer in PHPUnit using Craft’s `MailerInterface` and `MailerTrait`.
- Will this break existing Craft plugins that send emails?
- No, as long as plugins use Craft’s built-in mailer system (e.g., `Craft::$app->mailer`), they’ll automatically route through Mailcoach. Avoid hardcoding `Yii::$app->mailer` in custom code—use dependency injection or Craft’s service layer for flexibility.
- How do I secure the Mailcoach API key in production?
- Store the API key in your environment variables (e.g., `.env`) and reference it in `config/general.php` like this: `'mailcoachApiKey' => getenv('MAILCOACH_API_KEY')`. Never hardcode keys in version-controlled files. Use Craft’s `config/general.php` or a secrets manager for added security.
- Are there alternatives to Mailcoach for Craft CMS 5?
- Yes, consider **Postmark**, **AWS SES**, or **SendGrid** for transactional emails. For marketing-focused workflows, **Mailcoach** integrates tightly with Craft’s content management. Compare features like deliverability, pricing, and API stability before choosing.
- Can I customize email templates or dynamic content beyond Mailcoach’s defaults?
- Yes, use Craft’s Twig templates to override Mailcoach’s default emails. Place custom templates in `templates/emails/` and reference them in your mailer config. For dynamic content, pass variables via `Yii::$app->mailer->compose()->setTo(['user@example.com'])->setSubject('Hello')->setHtmlBody($yourTwigTemplate->render())`.
- How does this package handle GDPR compliance for email storage/logging?
- Mailcoach handles email content storage per their [privacy policy](https://mailcoach.app/privacy). Ensure your Craft project also complies with GDPR by anonymizing user data in logs and providing clear unsubscribe links. Use Craft’s `User` model methods like `sendPasswordResetEmail()` with Mailcoach’s built-in compliance features.