Skip to content

Latest commit

 

History

History
234 lines (185 loc) · 5.19 KB

README.md

File metadata and controls

234 lines (185 loc) · 5.19 KB

HeadooMailjetBundle

HeadooMailjetBundle is a Symfony2 Bundle, mainly aimed at processing MailJet API v3.

This wrapper use a deprecated API. Some documentation is available here : https://github.com/mailjet/mailjet-apiv3-php-simple You should migrate to this wrapper : https://github.com/mailjet/mailjet-apiv3-php

Installation

  1. Add to composer.json file :

    {
        "require": {
            "headoo/headoo-mailjet-bundle" : "1.0.x-dev"
        }
    }
  2. Install our dependencies using :

    $ php composer.phar update
  3. Register the bundle in your app/AppKernel.php:

     <?php
     ...
     public function registerBundles()
     {
         $bundles = array(
             ...
             new Headoo\HeadooMailjetBundle\HeadooMailjetBundle(),
             ...
         );
     ...

Usage

RESTful API as a service

Add api/secret keys in parameters.yml and it's up!

# app/parameters.yml
    mailjet_api_key: <your api key>
    mailjet_secret_key: <your secret key>

Now you can access RESTful API via DIC by calling headoo_mailjet_wrapper service:

	$mailjet = $this->container->get('headoo_mailjet_wrapper');

Responses (after using API)

You can access the following return values:

  • $mailjet->_response_code : like 200 for sucess
  • $mailjet->_response : return Mailjet datas (like the ID)

API examples usage

Email informations

    $params = array(
        "method" => "VIEW",
        "ID" => $id
    );

    $resutl = $mailjet->message($params);

Send email

  • Send an email :
	$params = array(
        "method" => "POST",
        "from" => "ms.mailjet@example.com",
        "to" => "mr.mailjet@example.com",
        "subject" => "Hello World!",
        "text" => "Greetings from Mailjet."
    );

    $result = $mailjet->sendEmail($params);
  • Send an email with some attachments (absolute paths on your computer) :
    $params = array(
        "method" => "POST",
        "from" => "ms.mailjet@example.com",
        "to" => "mr.mailjet@example.com",
        "subject" => "Hello World!",
        "text" => "Greetings from Mailjet.",
        "attachment" => array("@/path/to/first/file.txt", "@/path/to/second/file.txt")
    );

    $result = $mailjet->sendEmail($params);
  • Send an email with some inline attachments (absolute paths on your computer) :
    $params = array(
        "method" => "POST",
        "from" => "ms.mailjet@example.com",
        "to" => "mr.mailjet@example.com",
        "subject" => "Hello World!",
        "html" => "<html>Greetings from Mailjet <img src=\"cid:photo1.jpg\"><img src=\"cid:photo2.jpg\"></html>",
	"inlineattachment" => array("@/path/to/photo1.jpg", "@/path/to/photo2.jpg")
    );

    $result = $mailjet->sendEmail($params);
}

Account Settings

  • Get your profile information :
    $result = $mailjet->myprofile();
  • Update the field AddressCity of your profile :
    $params = array(
        "method" => "PUT",
        "AddressCity" => "New York"
    );

    $result = $mailjet->myprofile($params);

Contact Lists

  • Print the list of your contacts :
    $result = $mailjet->contact();
}
  • Update your contactData resource with ID $id, using arrays :
	$data = array(array('Name' => 'lastname', 'Value' => 'Jet'), array('Name' => 'firstname', 'Value' => 'Mail'));
	$params = array(
		'ID' => $id,
		'Data' => $data,
		'method' => 'PUT'
	);

	$result = $mailjet->contactdata($params);
  • Create a list with name $Lname :
    $params = array(
    	"method" => "POST",
    	"Name" => $Lname
    );

    $result = $mailjet->contactslist($params);
  • Get a list with ID $listID :
    $params = array(
    	"method" => "VIEW",
    	"ID" => $listID
    );

    $result = $mailjet->contactslist($params);

Note : You can use unique fields of resources instead of IDs, like "unique" => "test@gmail.com" in your params array for this example

  • Create a contact with email $Cemail :
    $params = array(
    	"method" => "POST",
    	"Email" => $Cemail
    );

    $result = $mailjet->contact($params);
  • Add the contact which ID is $contactID to the list which ID is $listID :
    $params = array(
    	"method" => "POST",
    	"ContactID" => $contactID,
    	"ListID" => $listID,
    	"IsActive" => "True"
    );

    $result = $mailjet->listrecipient($params);
  • Delete the list which ID is $listID :
    $params = array(
    	"method" => "DELETE",
    	"ID" => $listID
    );

    $result = $mailjet->contactslist($params);

Newsletters

  • Get the HTML body of the newsletter $newsletter_id :
    $params = array(
        "method" => "GET",
        "ID" => $newsletter_id
    );

    $result = $mailjet->getHTMLbody($params);

Note : You need to put an underscore character before your parameters that are not filters in a GET request

  • Add an HTML body $html_content to a newsletter $newsletter_id :
    $params = array(
        "method" => "PUT",
        "ID" => $newsletter_id,
        "html_content" => $html_content
    );

    $result = $mailjet->addHTMLbody($params);