Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Email Provider Laravel Package

bonnier/laravel-email-provider

Laravel package to fetch email template translations from a Translation/Email Manager. Provides BonnierMail::get($key, $replace, $locale) and an artisan command (bonnier:translation:get) to sync translations, configured via EMAIL_MANAGER_URL and service ID.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require bonnier/laravel-email-provider
    

    Publish the config file:

    php artisan vendor:publish --provider="Bonnier\EmailProvider\EmailProviderServiceProvider" --tag="config"
    
  2. Configuration: Edit config/email-provider.php to define your email templates, translations, and API endpoints for the Email Manager.

  3. First Use Case: Fetch and render a translated email template:

    use Bonnier\EmailProvider\EmailProvider;
    
    $emailProvider = app(EmailProvider::class);
    $emailContent = $emailProvider->get('welcome_email', ['name' => 'John']);
    

Implementation Patterns

Workflow: Fetching and Rendering Emails

  1. Fetch Translated Content:

    $content = $emailProvider->get('template_key', ['variables' => 'values']);
    
    • Replace template_key with your configured key in config/email-provider.php.
    • Pass an associative array for dynamic variables (e.g., ['name' => 'User']).
  2. Integration with Laravel Mail:

    Mail::send([], [], function ($message) use ($emailContent) {
        $message->subject('Welcome!');
        $message->setBody($emailContent);
    });
    
  3. Caching: Enable caching in the config to reduce API calls:

    'cache' => [
        'enabled' => true,
        'ttl' => 60, // Cache for 60 minutes
    ],
    

Dynamic Template Management

  • Use the EmailProvider facade or service container to fetch templates dynamically.
  • Extend the config to support multiple environments (e.g., dev, prod) with different API endpoints.

Gotchas and Tips

Pitfalls

  1. Deprecated Package:

    • Last release in 2018 may cause compatibility issues with modern Laravel (8/9/10). Test thoroughly.
    • Check for undocumented breaking changes in newer Laravel versions.
  2. API Dependency:

    • The package relies on an external Email Manager API. Downtime or rate limits may disrupt email delivery.
    • Implement fallback logic (e.g., local cache or static templates) if the API fails.
  3. Translation Overrides:

    • If translations are fetched dynamically, ensure your config/email-provider.php includes a fallback_locale to avoid missing translations.

Debugging

  • Enable Logging: Add debug logs to track API calls:

    'logging' => true,
    

    Check storage/logs/laravel.log for errors or failed requests.

  • Mock API Responses: For testing, override the HTTP client or use a mock API service to simulate responses.

Extension Points

  1. Custom HTTP Client: Bind a custom GuzzleHttp\Client to the container for advanced request handling:

    $this->app->bind(\GuzzleHttp\Client::class, function () {
        return new \GuzzleHttp\Client([
            'timeout' => 10,
            'headers' => ['Authorization' => 'Bearer token'],
        ]);
    });
    
  2. Template Preprocessing: Extend the Bonnier\EmailProvider\Contracts\TemplateRenderer interface to add custom logic (e.g., sanitization, placeholders).

  3. Event Listeners: Listen for email-provider.fetched events to log or modify fetched content:

    Event::listen('email-provider.fetched', function ($templateKey, $content) {
        // Custom logic here
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui