uneak/mailjet-bundle

Symfony MailjetBundle

Installs: 292

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

dev-master 2015-01-08 14:29 UTC

This package is auto-updated.

Last update: 2024-04-20 00:08:18 UTC


README

The Uneak Mailjet Bundle is a bundle used to help us to exploit the Mailjet API:

It includes an refactored version of Mailjet API client (found on https://www.mailjet.com/plugin/php-mailjet.class.php) with:

  • PSR-0 standards
  • A bundle configuration

Prerequisites

This version of the bundle requires Symfony 2.1+.

Installation

Download UneakMailjetBundle using composer

Add UneakMailjetBundle in your composer.json:

{
    "require": {
        "uneak/mailjet-bundle": "dev-master"
    }
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update uneak/mailjet-bundle

Composer will install the bundle to your project's vendor/uneak directory.

Enable the Bundle

Enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Uneak\MailjetBundle\MailjetBundle(),
    );
}

Configure Mailjet

In your config.yml:

mailjet:
    api_key: %mailjet_api_key%
    api_secret: %mailjet_api_secret%

Usage

The API is available with the "mailjet.email" service. In your controller (or elsewhere):

		$email = $this->get("mailjet.email");
		$email
				->setSender(new EmailUser("some@email.com", "Some Name"))
				->addReceiver(new EmailUser("some@email.com", "Some Name"))
				->addReceiver(new EmailUser("some@email.com", "Some Name"))
				->addCCReceiver(new EmailUser("some@email.com", "Some Name"))
				->setSubject("{{ hello }} {{ user.name }} at {{ user.email }}")
				->setBody("SomeBundle:Mail:test.html.twig")
				//->setBody("Hi {{ user.name }} at {{ user.email }}")
				->addParameter('hello', 'Salut')
				->setHtml(true)
				->sendOneByOne()
				;

or

		$email = $this->get("mailjet.email");
		$email
				->setSender(new EmailUser("some@email.com", "Some Name"))
				->addReceiver(new EmailUser("some@email.com", "Some Name"))
				->addReceiver(new EmailUser("some@email.com", "Some Name"))
				->addCCReceiver(new EmailUser("some@email.com", "Some Name"))
				->setSubject("{{ hello }} everybody")
				->setBody("SomeBundle:Mail:test.html.twig")
				//->setBody("Hello everybody")
				->addParameter('hello', 'Hi')
				->setHtml(true)
				->send()
				;