/mailjet-apiv3-php

[API v3] Mailjet (Zend) PHP Wrapper

Primary LanguagePHPMIT LicenseMIT

alt text

Build Status

Mailjet API Client.

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

Getting Started !

grab and save your Mailjet API credentials:

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

Initialize your Mailjet Client:

<?php

use \Mailjet\Resources;

$apikey = getenv('MJ_APIKEY_PUBLIC');
$apisecret = getenv('MJ_APIKEY_PRIVATE');

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

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

Make your first request

Get your user informations:

$me = $client->get(Resources::$User);

Read the result:

$me->success() will be false in case of error.

$me->getData() will contain the requested data, error message etc..

$me->getCount() will provide the number of element requested

Debug

$me->getStatus() contains the server http response code

$me->request->getUrl() contains the call url

$me->request->getFilters() contains the provided filters

and $me->request->getBody() contains the request body

Send Emails

<?php

$email = [
  'FromName' => 'Roger Smith',
  'FromEmail' => 'roger@smith.com',
  'Subject' => 'Hey!',
  'Text-Part' => 'Hello Humans!',
  'Html-Part' => '<p>Hello Humans</p>',
  'Recipients' => [
      ['Email' => 'stan@smith.com', 'Name' => 'Stan'],
      ['Email' => 'francine@smith.com', 'Name' => 'Francine']
  ]
];

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

?>

Call a resource with an action

<?php

$client->get(Resources::$ContactGetcontactslists, ['id' => $contact_id]);

?>

Copy/Paste Examples

View a single contact

<?php

namespace example;
use \Mailjet\Resources;

require 'vendor/autoload.php';

$apikey = getenv('MJ_APIKEY_PUBLIC');
$apisecret = getenv('MJ_APIKEY_PRIVATE');

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

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

if ($response->success())
{
  $contact = $response->getData();
  // ...
}

?>

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.