PHP code example of heterodoks / laravel-sendy

1. Go to this page and download the library: Download heterodoks/laravel-sendy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

heterodoks / laravel-sendy example snippets


  use Heterodoks\LaravelSendy\Facades\Sendy;

  // Basic subscription
  $result = Sendy::subscribe('list_id', '[email protected]');

  // With additional details
  $result = Sendy::subscribe(
      'list_id',
      '[email protected]',
      'John Doe',
      ['custom_field' => 'value'],
      true // GDPR consent
  );
  

  $result = Sendy::unsubscribe('list_id', '[email protected]');
  

  $status = Sendy::getSubscriptionStatus('list_id', '[email protected]');
  // Returns: "Subscribed", "Unsubscribed", "Unconfirmed", "Bounced", "Soft bounced", or "Complained"
  

  $count = Sendy::getActiveSubscriberCount('list_id');
  

  $result = Sendy::createCampaign(
      'John Doe',                  // From Name
      '[email protected]',         // From Email
      '[email protected]',        // Reply To
      'Campaign Title',           // Title
      'Email Subject',            // Subject
      'Plain text version',       // Plain Text
      '<p>HTML version</p>',      // HTML Text
      'list-id',                  // List ID or array of List IDs
      'brand-id',                 // Optional: Brand ID
      'utm_source=newsletter'     // Optional: Query String
  );  

  $result = Sendy::createDraftCampaign(
      'John Doe',
      '[email protected]',
      '[email protected]',
      'Campaign Title',
      'Email Subject',
      'Plain text version',
      '<p>HTML version</p>',
      ['list-id-1', 'list-id-2'], // Multiple lists
      'brand-id',
      'utm_source=newsletter'
  );  

  $result = Sendy::scheduleCampaign(
      'John Doe',
      '[email protected]',
      '[email protected]',
      'Campaign Title',
      'Email Subject',
      'Plain text version',
      '<p>HTML version</p>',
      'list-id',
      '2024-12-31 23:59:59',     // Schedule datetime
      'brand-id',
      'utm_source=newsletter'
  );  

  $result = Sendy::deleteSubscriber('list_id', '[email protected]');
  

  // Available statuses: active, unconfirmed, unsubscribed, bounced, complained
  $count = Sendy::getSubscriberCountByStatus('list_id', 'active');
  

  // Get total active subscribers for default brand
  $total = Sendy::getTotalActiveSubscribers();

  // Get total active subscribers for specific brand
  $total = Sendy::getTotalActiveSubscribers('brand-id');
  

  // Basic update
  $result = Sendy::updateSubscriber('list_id', '[email protected]', 'New Name');

  // Update with custom fields
  $result = Sendy::updateSubscriber(
      'list_id',
      '[email protected]',
      'New Name',
      ['custom_field' => 'new_value']
  );
  
bash
  php artisan vendor:publish --tag="sendy-config"