Git Product home page Git Product logo

iadotmailer's Introduction

dotMailer API v2 PHP client

Forked from https://github.com/romanpitak/dotMailer-API-v2-PHP-client

Latest Stable Version Total Downloads License Code Climate Codacy Badge

(c) 2014-2016 Roman Piták, http://pitak.net [email protected]

PHP client library for the dotMailer v2 (REST) API with multiple accounts support!

Full implementation according to the http://api.dotmailer.com/v2/help/wadl

Type hinting support for objects and resources (not yet for arrays).

Installation

The best way to install is to use the Composer dependency manager.

Add the repository in your composer.json :

	"repositories": [
      {
        "type": "vcs",
        "no-api": true,
        "url": "[email protected]:InteractAgency/IaDotMailer.git"
      }
	],
composer require interact/iadotmailer

Usage

Single account usage

<?php
require_once('vendor/autoload.php');

$credentials = array(
    Container::USERNAME => '[email protected]',
    Container::PASSWORD => 'YYYYYYYYYYYYYYYYYYYYYYYYYYY'
);

$resources = Container::newResources($credentials);

echo $resources->GetAccountInfo();

Multiple accounts usage

<?php
require_once('vendor/autoload.php');

$credentials = array(
    'master' => array(
        Container::USERNAME => '[email protected]',
        Container::PASSWORD => 'YYYYYYYYYYYYYYYYYYYYYYYYYYY'
    ),
    'group1' => array(
        'g1-account1' => array(
            Container::USERNAME => '[email protected]',
            Container::PASSWORD => 'YYYYYYYYYYYYYYYYYYYYYYYYYYY'
        ),
        'g1-account2' => array(
            Container::USERNAME => '[email protected]',
            Container::PASSWORD => 'YYYYYYYYYYYYYYYYYYYYYYYYYYY'
        )
    )
);

$container = Container::newContainer($credentials);

echo $container->getResources('master')->GetSegments();

$dataField = new ApiDataField();
$dataField->name = 'MY_DATA_FIELD';
$dataField->type = ApiDataTypes::STRING;
$dataField->visibility = ApiDataFieldVisibility::HIDDEN;

foreach ($container->group1 as $resources) {
    try {
        $resources->PostDataFields($dataField);
        echo 'OK';
    } catch (Exception $e) {
        echo 'Already exists';
    }
}

Create campaign with images (real life example)

<?php
// find the correct custom from address
$customFromAddresses = $account->GetCustomFromAddresses();
$customFromAddress = null;
foreach ($customFromAddresses as $cfa) {
    if ('[email protected]' == $cfa->email) {
        $customFromAddress = $cfa;
        break;
    }
}
if (is_null($customFromAddress)) {
    throw new \Exception('Custom from address not found in the account.');
}

// Create campaign to get campaign ID
// we need the campaign id later to create image folder
$campaign = new ApiCampaign();
$campaign->name = 'My API Campaign';
$campaign->subject = 'Api Works';
$campaign->fromName = "Roman Piták";
$campaign->fromAddress = $customFromAddress->toJson();
// empty content (must include unsubscribe links)
$campaign->htmlContent = '<a href="http://$unsub$">UNSUB</a>';
$campaign->plainTextContent = 'http://$unsub$';
// save campaign
$campaign = $account->PostCampaigns($campaign);

// Create image folder
$folder = new ApiImageFolder();
$folder->name = date('c') . ' cid=' . (string)$campaign->id;
$folder = $account->PostImageFolder(new XsInt(0), $folder);
$folderId = $folder->id;

// Upload images
foreach ($images as $baseName => $data) {
    $apiFileMedia = new ApiFileMedia();
    $apiFileMedia->fileName = pathinfo($data['file'], PATHINFO_FILENAME);
    $apiFileMedia->data = base64_encode(file_get_contents($data['file']));
    $apiImage = $account->PostImageFolderImages($folderId, $apiFileMedia);
    // set the dotMailer src for the images
    $images[$baseName]['src'] = (string)$apiImage->path;
}

// UPDATE CAMPAIGN
$campaign->id = $campaign->id->toJson();
// getIndexHtml returns the html of the email with the correct src attribute for the images
// it uses the $images array
$htmlContent = getIndexHtml($includeDirectory);
$campaign->htmlContent = $htmlContent;
$html2text = new Html2Text($htmlContent);
$campaign->plainTextContent = $html2text->get_text();
$account->UpdateCampaign($campaign);

iadotmailer's People

Contributors

romanpitak avatar vrochereau avatar christian-thomas avatar danbovey avatar railsguy avatar ishakuta avatar willitscale avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.