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
-
Add to
composer.json
file :{ "require": { "headoo/headoo-mailjet-bundle" : "1.0.x-dev" } }
-
Install our dependencies using :
$ php composer.phar update
-
Register the bundle in your
app/AppKernel.php
:<?php ... public function registerBundles() { $bundles = array( ... new Headoo\HeadooMailjetBundle\HeadooMailjetBundle(), ... ); ...
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');
You can access the following return values:
$mailjet->_response_code
: like200
for sucess$mailjet->_response
: return Mailjet datas (like the ID)
$params = array(
"method" => "VIEW",
"ID" => $id
);
$resutl = $mailjet->message($params);
- 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);
}
- 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);
- 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);
- 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);