mailjet-apiv3-php 0 travis-ci Packagist phpunit

[API v3] Mailjet PHP Wrapper

alt text

Codacy Badge Build Status MIT License Current Version

Mailjet API Client.

Check out all the resources and all the PHP code examples on the official documentation: Maijlet Documentation

Requirements

PHP >= 5.4

Installation

composer require mailjet/mailjet-apiv3-php

Without composer:

Clone or Download this repository that already contains all the dependencies and the vendor/autoload.php file. If you encounter any issue, please post it here and not on the mirror repository.

Getting Started !

grab and save your Mailjet API credentials. It will create some variables available in your code, via the getenv function:


export MJ_APIKEY_PUBLIC='your api key'
export MJ_APIKEY_PRIVATE='your api secret'

Initialize your Mailjet Client:

<?php

use \Mailjet\Resources;

// getenv will allow us to get the MJ_APIKEY_PUBLIC/PRIVATE variables we created before
$apikey = getenv('MJ_APIKEY_PUBLIC');
$apisecret = getenv('MJ_APIKEY_PRIVATE');

// or

$apikey = 'my api key';
$apisecret = 'my api secrret';

$mj = new \Mailjet\Client($apikey, $apisecret);
?>

It’s as easy as 1, 2, 3 !

Make your first call

<?php
require 'vendor/autoload.php';

use \Mailjet\Resources;

// use your saved credentials
$mj = new \Mailjet\Client(getenv('MJ_APIKEY_PUBLIC'), getenv('MJ_APIKEY_PRIVATE'));

// Resources are all located in the Resources class
$response = $mj->get(Resources::$Contact);

/*
  Read the response
*/
if ($response->success())
  var_dump($response->getData());
else
  var_dump($response->getStatus());

Filtering resources

The Mailjet API provides a set of general filters that can be applied to a GET request for each resource. In addition to these general filters, each API resource has its own filters that can be used when performing the GET

<?php

$filters = ['Limit' => '150'];

$response = $mj->get(Resources::$Contact, ['filters' => $filters]);

Send transactional emails

<?php

$body = [
    'FromEmail' => "[email protected]",
    'FromName' => "Mailjet Pilot",
    'Subject' => "Your email flight plan!",
    'Text-part' => "Dear passenger, welcome to Mailjet! May the delivery force be with you!",
    'Html-part' => "<h3>Dear passenger, welcome to Mailjet!</h3><br />May the delivery force be with you!",
    'Recipients' => [['Email' => "[email protected]"]]
];

$response = $mj->post(Resources::$Email, ['body' => $body]);

Send marketing campaign

To send your first newsletter, you need to have at least one active sender address in the Sender domains & addresses section.

<?php

$body = [
    'Recipients' => [
        [
            'Email' => "[email protected]",
            'Name' => "Mailjet"
        ]
    ]
];

$response = $mj->post(Resources::$NewsletterTest, ['id' => $id, 'body' => $body]);

?>

Event API - real time notifications

The Event API offer a real-time notification through http request on any events related to the messages you sent. The main supported events are open, click, bounce, spam, blocked, unsub and sent. This event notification works for transactional and marketing emails.

The endpoint is an URL our server will call for each event (it can lead to a lot of hits !). You can use the API to setup a new endpoint using the /eventcallbackurl resource. Alternatively, you can configure this in your account preferences, in the Event Tracking section.

<?php

$body = [
    'EventType' => "open",
    'Url' => "https://mydomain.com/event_handler"
];

$response = $mj->post(Resources::$Eventcallbackurl, ['body' => $body]);

Statistics

The Mailjet API offers resources to extracts information for every messages you send. You can also filter through the message statistics to view specific metrics for your messages.

<?php

$response = $mj->get(Resources::$Message, ['id' => $id]);

Parse API - Inbound emails

The Parse API allows you to have inbound emails parsed and their content delivered to a webhook of your choice. In order to begin receiving emails to your webhook, create a new instance of the Parse API via a POST request on the /parseroute resource.

<?php

$body = [
    'Url' => 'https://www.mydomain.com/mj_parse.php'
];

$response = $mj->post(Resources::$Parseroute, ['body' => $body]);

Send a pull request

  • Fork the project.
  • Create a topic branch.
  • Implement your feature or bug fix.
  • Add documentation for your feature or bug fix.
  • Add specs for your feature or bug fix.
  • Commit and push your changes.
  • Submit a pull request. Please do not include changes to the gemspec, or version file.

Related Repositories

mailjet-apiv3-php-simple

mailjet-apiv3-php-simple

[API v3] Simple PHP wrapper for the Mailjet API /!\ [DEPRECATED - SEE README] /!\ ...

mailjet-apiv3-php

mailjet-apiv3-php

[API v3] Mailjet PHP Wrapper ...

mailjet-apiv3-php-no-composer

mailjet-apiv3-php-no-composer

[API v3] Mailjet PHP Wrapper bundled with composer dependencies ...


Top Contributors

orliesaurus peschee GuillaumeBadi Narno mnapoli Aridjar axi hilnius isetz flegoff bretto36 CharlesCollas kachar schojniak szepeviktor

Dependencies

package version
dev phpunit/phpunit ^4.8
php >=5.4.0
guzzlehttp/guzzle ~6.0|~5.3

Releases

-   v1.1.7 zip tar
-   v1.1.6 zip tar
-   v1.1.5 zip tar
-   v1.1.4 zip tar
-   v1.1.3 zip tar
-   v1.1.2 zip tar
-   v1.1.1 zip tar
-   v1.1.0 zip tar
-   v1.0.3 zip tar
-   v1.0.2 zip tar
-   v1.0.1 zip tar
-   v1.0.0 zip tar
-   0.0.1 zip tar