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

Managesend Php Laravel Package

dreamcampaigns/managesend-php

PHP client library for the DreamCampaigns (Managesend) API. Authenticate with API key/secret and send transactional “Smart” emails via the REST client. Install with Composer or manually with the included autoloader. Supports PHP 5.3–7.4.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require dreamcampaigns/managesend-php
    

    Or manually include the autoloader:

    require_once __DIR__ . '/vendor/autoload.php';
    
  2. Environment Configuration (Recommended): Add to .env:

    MANAGESEND_TOKEN_KEY=your_api_key
    MANAGESEND_TOKEN_SECRET=your_api_secret
    MANAGESEND_CLIENT_ID=your_client_id
    
  3. First Use Case: Initialize the client and send a test email:

    $client = new \Managesend\RestClient();
    $result = $client->transactional()->sendSmartEmail(
        env('MANAGESEND_CLIENT_ID'),
        [
            'toEmail' => 'test@example.com',
            'toName' => 'Test User',
            'data' => ['promoCode' => 'TEST123']
        ]
    );
    print $result->getData()->getMessageId();
    

Implementation Patterns

Core Workflows

  1. Transactional Emails/SMS:

    // Smart Email
    $client->transactional()->sendSmartEmail($clientId, $params);
    
    // Dynamic SMS
    $client->transactional()->sendDynamicSms($clientId, $params);
    
  2. Campaign Management:

    // Get sent campaigns
    $campaigns = $client->emailCampaign()->getCampaignsSent();
    
    // Trigger a campaign
    $client->emailCampaign()->triggerCampaign($campaignId, $params);
    
  3. Subscriber Lists:

    // Add subscriber
    $client->lists()->addSubscriber($listId, $email, $params);
    
    // Get list subscribers
    $subscribers = $client->lists()->getSubscriberList($listId);
    

Integration Tips

  • Service Provider Pattern: Register the client in AppServiceProvider:

    public function register()
    {
        $this->app->singleton(\Managesend\RestClient::class, function ($app) {
            return new \Managesend\RestClient(
                env('MANAGESEND_TOKEN_KEY'),
                env('MANAGESEND_TOKEN_SECRET'),
                env('MANAGESEND_CLIENT_ID')
            );
        });
    }
    
  • Dependency Injection: Inject the client into controllers/services:

    public function __construct(private \Managesend\RestClient $client) {}
    
  • Queue Jobs: Dispatch email/SMS jobs for async processing:

    SendEmailJob::dispatch($client, $params)->onQueue('emails');
    

Common Use Cases

Use Case Implementation Pattern
User welcome emails sendSmartEmail with dynamic merge tags
Password reset SMS sendDynamicSms with template variables
Newsletter campaigns triggerCampaign with segmented lists
Subscriber management addSubscriber/removeSubscriber via API

Gotchas and Tips

Pitfalls

  1. Authentication:

    • Issue: Missing clientId in requests (throws 401 Unauthorized).
    • Fix: Always set clientId via $client->setClientId() or constructor.
  2. Rate Limiting:

    • Issue: API returns 429 Too Many Requests for rapid calls.
    • Fix: Implement exponential backoff in retries:
      $client->setRetryPolicy(new \Managesend\RetryPolicy(3, 1000));
      
  3. Deprecated Methods:

Debugging

  • Enable Debug Mode:

    $client->setDebug(true); // Logs requests/responses to `storage/logs/managesend.log`
    
  • Response Inspection:

    $response = $result->getResponse();
    print $response->getBody(); // Raw response body
    print_r($response->getHeaders()); // Response headers
    

Extension Points

  1. Custom Requests: Override the RestClient to add headers or modify requests:

    class CustomClient extends \Managesend\RestClient {
        public function request($method, $url, $params = []) {
            $params['headers']['X-Custom-Header'] = 'value';
            return parent::request($method, $url, $params);
        }
    }
    
  2. Response Wrapping: Extend Result to add custom logic:

    class CustomResult extends \Managesend\Result {
        public function getCustomData() {
            return $this->getData()->toArray()['custom_field'];
        }
    }
    
  3. Environment Fallbacks: Use Laravel’s config() helper for dynamic API keys:

    $client = new \Managesend\RestClient(
        config('services.managesend.key'),
        config('services.managesend.secret'),
        config('services.managesend.client_id')
    );
    

Configuration Quirks

  • Client ID Scope:

    • Account-level keys require setClientId() per request.
    • Client-level keys can omit this step.
  • Merge Tags:

    • Smart emails use data array for dynamic content (e.g., data['promoCode']).
    • Ensure keys match your template variables exactly.
  • Timeouts:

    • Default timeout is 30s. Adjust via:
      $client->setTimeout(60); // 60 seconds
      
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.
craftcms/url-validator
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony