Giter Site home page Giter Site logo

luya-mailjet's Introduction

LUYA Logo

LUYA Mailjet

LUYA Tests Total Downloads Latest Stable Version Test Coverage Maintainability

LUYA and Yii Framework integration for Mailjet service.

Contains:

  • Yii Framework BaseMailer for Transaction E-Mails trough API.
  • Interface for Subscription Mail Sync including CLI command for Synchronisation.
  • A PHP library to convert MJML content into Mailjet Passport json format.
  • LUYA Admin Module to convert MJML into HTML based on MJML.io API.
  • LUYA Active Window to retrieve informations about a given User E-Mail.
  • A Widget to subscribe to a List with double opt in (can be disabled).
  • SMS Sending helpers
  • Yii 2 Queue Job to send mails with a template

Installation

Install the extension through composer:

composer require luyadev/luya-mailjet

Add to config:

'components' => [
    //...
    'mailjet' => [
        'class' => 'luya\mailjet\Client',
        'apiKey' => '...',
        'apiSecret' => '...',
    ],
    'mailer' => [
        'class' => 'luya\mailjet\Mailer',
    ],
]

Basic Send Mail

Sending transactional E-Mail:

Yii::$app->mailer->compose()
    ->setFrom('[email protected]')
    ->setTo('[email protected]')
    ->setSubject('Message subject')
    ->setTextBody('Plain text content')
    ->setHtmlBody('<b>HTML content</b>')
    ->send();

Send a transactional E-Mail based on the Template id stored in Mailjet:

Yii::$app->mailer->compose()
    ->setTemplate(484590)
    ->setVariables(['lastname' => 'Lastname Value'])
    ->setTo(['[email protected]'])
    ->send();

MJML to HTML

With version 1.3 of LUYA Mailjet library there is an admin module you can configured in order to parser MJML into HTML, therefore add the module to your configuration and provide mjml.io API keys:

'modules' => [
    //...
    'mailjetadmin' => [
        'class' => 'luya\mailjet\admin\Module',
        'mjmlApiApplicationId' => 'ApplicationIdFromMjml.io',
        'mjmlApiSecretKey' => 'ApplicationSecretFromMjml.io',
    ]
]

Afterwards you can retrieve and render the HTML of MJML template with:

luya\mailjet\models\Template::renderHtml('slug', ['foo' => 'bar']);

luya-mailjet's People

Contributors

dependabot[bot] avatar hbugdoll avatar johnnymcweed avatar nadar avatar rolandschaub avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

luya-mailjet's Issues

mjml parser

added new options to

  • parse the mjml to html ON Request, instead while saving
  • option to parse the variables within the mjml content instead of html

(@rolandschaub)

Error when setting "defaultTemplateErrorReporting" without templates

'mailer' => [
    'class' => 'luya\mailjet\Mailer',
    'defaultTemplateErrorReporting' =>'[email protected]',
],
'forms' => [
    'class' => 'luya\forms\Forms',
    'emailMessage' => function (SubmissionEmail $email, Forms $form) {
        // your custom mailer integration is here, ensure to return a boolean
        // value whether sending was successfull or not!    
        $x = \Yii::$app->mailer->compose()
            ->setTo($email->getRecipients())
            ->setSubject($email->getSubject())
            ->setTextBody(strip_tags($email->getSummaryHtml()))
            ->setHtmlBody($email->getSummaryHtml())
            ->send();

        var_dump(\Yii::$app->mailer->lastError);
        exit;
    }
]
Error message
string(1293) "array (
  'Messages' => 
  array (
    0 => 
    array (
      'Status' => 'error',
      'Errors' => 
      array (
        0 => 
        array (
          'ErrorIdentifier' => '74d2cbc4-df26-4f7e-94e9-d13110a588bb',
          'ErrorCode' => 'send-0016',
          'StatusCode' => 400,
          'ErrorMessage' => '"TemplateLanguage" is not set while "TemplateErrorReporting" or "TemplateErrorDeliver" properties are.',
          'ErrorRelatedTo' => 
          array (
            0 => 'TemplateLanguage',
            1 => 'TemplateErrorDeliver',
            2 => 'TemplateErrorReporting',
          ),
        ),
      ),
    ),
  ),
) | array (
  'Messages' => 
  array (
    0 => 
    array (
      'Status' => 'error',
      'Errors' => 
      array (
        0 => 
        array (
          'ErrorIdentifier' => '74d2cbc4-df26-4f7e-94e9-d13110a588bb',
          'ErrorCode' => 'send-0016',
          'StatusCode' => 400,
          'ErrorMessage' => '"TemplateLanguage" is not set while "TemplateErrorReporting" or "TemplateErrorDeliver" properties are.',
          'ErrorRelatedTo' => 
          array (
            0 => 'TemplateLanguage',
            1 => 'TemplateErrorDeliver',
            2 => 'TemplateErrorReporting',
          ),
        ),
      ),
    ),
  ),
) | 'Bad Request'"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.