PHP code example of unione / unione-php

1. Go to this page and download the library: Download unione/unione-php 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/ */

    

unione / unione-php example snippets


  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  // Example for EU instance.
  $client = new Unione\UnioneClient('YOUR-API-KEY', 'eu1.unione.io');

  $recipients = [
    [
      "email" => '[email protected]',
      "substitutions" => [
        "to_name" => "John Smith"
      ],
    ],
    [
      "email" => '[email protected]',
      "substitutions" => [
        "to_name" => "Liza Frank"
      ],
    ]
  ];

  $body = [
    "html" => "<b>Test mail, {{to_name}}</b>",
    "plaintext" => "Hello, {{to_name}}",
    "amp" => "<!doctype html><html amp4email><head> <meta charset=\"utf-8\"><script async src=\"https://cdn.ampproject.org/v0.js\"></script> <style amp4email-boilerplate>body[visibility:hidden]</style></head><body> Hello, AMP4EMAIL world.</body></html>"
  ];

  // You can use email object can be used to prepare the message array.
  // But the email send method accepts an array, that can be composed without
  // SDK utils.
  $mail = new Unione\Model\Email($recipients, $body);
  $mail->setFromEmail('[email protected]');
  $mail->setSubject('test letter');
  $response = $client->emails()->send($mail->toArray());

  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');

  $params = [
    "from_email" => "[email protected]",
    "from_name" => "John Smith",
    "to_email" => "[email protected]"
  ];
  $response = $client->emails()->subscribe($params);

  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');

  $params = [
    "template" => [
      "name" => "First template",
      "body" => [
        "html" => "<b>Hello, {{to_name}}</b>",
        "plaintext" => "Hello, {{to_name}}",
        "amp" => "<!doctype html><html amp4email><head> <meta charset=\"utf-8\"><script async src=\"https://cdn.ampproject.org/v0.js\"></script> <style amp4email-boilerplate>body[visibility:hidden]</style></head><body> Hello, AMP4EMAIL world.</body></html>"
      ],
      "subject" => "Test template mail",
      "from_email" => "[email protected]",
      "from_name" => "Example From",
    ]
  ];
  $response = $client->templates()->set($params);

  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->templates()->get('YOUR-TEMPLATE-ID');

  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');

  $params = [
    "limit" => 50,
    "offset" => 0
  ];
  $response = $client->templates()->list($params);

  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->templates()->delete('YOUR-TEMPLATE-ID');

  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');

  $params = [
    "url" => "https://yourhost.example.com/unione-webhook",
    "events" => [
      "email_status" => [
        "delivered",
        "opened",
        "clicked",
        "unsubscribed",
        "soft_bounced",
        "hard_bounced",
        "spam"
      ]
    ]
  ];
  $response = $client->webhooks()->set($params);


$client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
// $body contains a callback request body.
if ($client->webhooks()->verify($body) === TRUE) {
  // The webhook is confirmed, result can be processed.
}

  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->webhooks()->get('YOUR-WEBHOOK-URL');

  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->webhooks()->list();

  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->webhooks()->delete('YOUR-WEBHOOK-URL');

  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME');
  $response = $client->httpRequest('suppression/set.json', ["email" => "[email protected]", "cause" => "unsubscribed"]);

  $container = [];
  $history = Middleware::history($container);
  $handlerStack = HandlerStack::create();
  $handlerStack->push($history);
  $config = ['handler' => $handlerStack];
  $client = new Unione\UnioneClient('YOUR-API-KEY', 'YOUR-HOST-NAME', $config);
bash
composer