Giter Club home page Giter Club logo

mailjet-apiv3-php's Introduction

[API v3] Mailjet (Zend) PHP Wrapper

Introduction

Provides a simple PHP library for the last version of the MailJet API. The goal of this component is to simplify the usage of the MailJet API for PHP developers.

Beware this library has been designed for people using Zend. If you do not use Zend, you might be interested by our mailjet-apiv3-php-simple repository with a simpler wrapper based on cURL.

Prerequisites

Make sure to have the following details:

  • Mailjet API Key
  • Mailjet API Secret Key
  • PHP (We've built this library to work on 5.4)
  • This library

Installation

First clone the repository

git clone [email protected]:mailjet/mailjet-apiv3-php.git

or download the zip tarball

https://github.com/mailjet/mailjet-apiv3-php/archive/master.zip

Then use Composer install

curl -s https://getcomposer.org/installer | php
php composer.phar install

Usage

To use the Mailjet PHP library ensure you've installed it correctly then simply create a file in which you will write your code. Create an empty file and name it mailjetapi.php.

The first thing to do is to import the required namespaces and files:

include_once __DIR__ . '/vendor/autoload.php';
use Mailjet\Api as MailjetApi;
use Mailjet\Model\Apitoken;

Be Careful: Make sure you've kept the directory structure intact or the include function will not be able to find the file which autoloads the wrapper's classes Next, you will add your credentials:

$APIKey    = 'MY_API_KEY_VALUE';
$secretKey = 'MY_API_SECRET_KEY_VALUE';

Obviously you need to replace the values within the quotes with your own, that you can find at the following URL Mailjet API Keys once you've registered and logged in Mailjet.

Now the fun begins, create a new object which takes as arguments your credentials:

$wrapper = new MailjetApi\Api($APIKey, $secretKey);

This basically, starts the engine. Now what you're going to do next depends on what you want to POST, DELETE, PUT or GET from the Mailjet servers throught the API.

Next you will specifying which resource to call this way:

$wrapper->resourceName()

For example if I want to use the resource ApiKey (which tells me a bunch of information about my ApiKey) I will do:

$wrapper->apikey()

NOTE: Make sure you've been using the correct namespace at the start of the file, each resource has its own namespace.

Examples

A function that creates a list of contacts $Lname

function createList($wrapper,$Lname) {
     $apicall = $wrapper->contactslist();
     $newList = new Contactslist();
     $newList->setName($Lname);
     $createList = $apicall->create($newList);
     echo "success - created list\n";
     return $createList->getID();
}

A function that creates a Contact $buddy

function createContact($wrapper, $buddy) {
     $apicall = $wrapper->contact();
     $newContact = new Contact();
     $newContact->setEmail($buddy);
     $createContact = $apicall->create($newContact);
     echo "success - created contact\n";
     return $createContact->getID();
}

A function that adds a given contact ID $buddyID to a given list $ListID

function addContactToList($wrapper,$ListID,$buddyID) {
    $apicall = $wrapper->Listrecipient();
    $newContactToList = new Listrecipient();
    $newContactToList->setListID($ListID);
    $newContactToList->setContactID($buddyID);
    $addContactToList = $apicall->create($newContactToList);
    echo "success - created contact to list\n";
    return $addContactToList;
}

Reporting issues

Open an issue on github or email one of the maintainers. That would be me ;) (orlando at mailjet dot com)

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.