Laravel package for Mailjet API V3 and Laravel Mailjet Mail Transport

Overview

Laravel Mailjet

Build Status Packagist Packagist GitHub license Documentation

Laravel package for handling Mailjet API v3 using this wrapper: https://github.com/mailjet/mailjet-apiv3-php

It also provides a mailjetTransport for Laravel mail feature

Installation

First, include the package in your dependencies:

composer require mailjet/laravel-mailjet

Then, you need to add some informations in your configuration files. You can find your Mailjet API key/secret here. Please also set your email from address and name.

  • In the providers array:
'providers' => [
    ...
    Mailjet\LaravelMailjet\MailjetServiceProvider::class,
    ...
]
  • In the aliases array:
'aliases' => [
    ...
    'Mailjet' => Mailjet\LaravelMailjet\Facades\Mailjet::class,
    ...
]
  • In the services.php file:
'mailjet' => [
    'key' => env('MAILJET_APIKEY'),
    'secret' => env('MAILJET_APISECRET'),
]
  • In your .env file:
MAILJET_APIKEY=YOUR_APIKEY
MAILJET_APISECRET=YOUR_APISECRET
MAIL_FROM_ADDRESS=YOUR_EMAIL_FROM_ADDRESS
MAIL_FROM_NAME=YOU_FROM_NAME

Full configuration

For details head to configuration doc.

Mail driver configuration

In order to use Mailjet as your Mail driver, you need to update the mail driver in your config/mail.php or your .env file to MAIL_MAILER=mailjet (for Laravel 6 and older use MAIL_DRIVER constant instead), and make sure you are using a valid and authorised from email address configured on your Mailjet account. The sending email addresses and domain can be managed here

For Laravel 7+ you also need to specify new available mail driver in config/mail.php:

'mailers' => [
    ...

    'mailjet' => [
        'transport' => 'mailjet',
    ],
],

For usage, please check the Laravel mail documentation

Usage

In order to usage this package, you first need to import Mailjet Facade in your code:

use Mailjet\LaravelMailjet\Facades\Mailjet;

Then, in your code you can use one of the methods available in the MailjetServices.

Low level API methods:

  • Mailjet::get($resource, $args, $options)
  • Mailjet::post($resource, $args, $options)
  • Mailjet::put($resource, $args, $options)
  • Mailjet::delete($resource, $args, $options)

High level API methods:

  • Mailjet::getAllLists($filters)
  • Mailjet::createList($body)
  • Mailjet::getListRecipients($filters)
  • Mailjet::getSingleContact($id)
  • Mailjet::createContact($body)
  • Mailjet::createListRecipient($body)
  • Mailjet::editListrecipient($id, $body)

For more informations about the filters you can use in each methods, refer to the Mailjet API documentation

All method return Mailjet\Response or throw a MailjetException in case of API error.

You can also get the Mailjet API client with the method getClient() and make your own custom request to Mailjet API.

If you need to delete a contact, you need to register ContactsServiceProvider:

  • In the providers array:
'providers' => [
    ...
    \Mailjet\LaravelMailjet\Providers\ContactsServiceProvider::class,
    ...
]

and use it:

public function handle(ContactsV4Service $contactsV4Service)
{
    $response = $contactsV4Service->delete(351406781);
    ...
}

ToDo

  • Add additional unit tests to increase code coverage.
Comments
  • Add support for laravel 7.x

    Add support for laravel 7.x

    Hello guys. I'm using this fabulous library for handling emails inside my laravel project. Now my company needs to update Laravel to 7.x but this package does not support it since the laravel/tinker requirment does not match...

    Laravel 7.x needs laravel/tinker at ^2.0 and this package is at ~1.0.

    Could you update the requirement to be compatible with Laravel 7.x ?

    Thank you so much.

    opened by didix16 18
  • Documentation: Missing Mail configuration

    Documentation: Missing Mail configuration

    Hi Guys, Do we need any of MAIL_DRIVER=smtp MAIL_HOST=mail MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null

    to run mailjet ?

    Other question, does the alias is neccessery ? If yes where it sohuld go in Lumen in this case ?

    Thank you

    Regards

    opened by kimek 14
  • Accept laravel 6

    Accept laravel 6

    Right now your composer file just accept Laravel 5.6, the package can't be used on 5.4, 5.5, 5.8, 6.0 or any other version. And i have tested and it work on that versions, so it should be able to install it there.

    So i just updated the composer.json to accept any laravel version after or equals to 5.0

    opened by skalero01 10
  • Cannot create instance of \Mailjet\Client while API key is NULL

    Cannot create instance of \Mailjet\Client while API key is NULL

    Hello i tried to use Mailjet as a new driver but i get this exception when i try to send a mail.

    I configured .env , mail.php , services.php

    I really need to send mails like this : Mail::to('[email protected]')->send(new MassiveEmail($subject , $bodyMessage , $files));

    Because i use markdown.

    Let me know where i'm doing wrong

    Thanks in advance

    opened by mourareaupro 10
  • Latest Update Not Working

    Latest Update Not Working

    Thanks for updating the package. Unfortunately we still cannot work with it.

    With a fresh version of Laravel I get:

    Problem 1 - Can only install one of: laravel/tinker[1.x-dev, v2.5.0]. - Can only install one of: laravel/tinker[v2.5.0, 1.x-dev]. - Can only install one of: laravel/tinker[1.x-dev, v2.5.0]. - mailjet/laravel-mailjet 2.1.0 requires laravel/tinker ~1.0 -> satisfiable by laravel/tinker[1.x-dev]. - Installation request for mailjet/laravel-mailjet ^2.1 -> satisfiable by mailjet/laravel-mailjet[2.1.0]. - Installation request for laravel/tinker (locked at v2.5.0, required as ^2.5) -> satisfiable by laravel/tinker[v2.5.0].

    According to the main code tab none of the files have been updated recently and the update has been applied to 1.1.0 as opposed to 2.X so I'm wondering if the work was done on the wrong version or if the work needs to be merged in.

    The changes marked in the latest only show 2 archives: https://github.com/mailjet/laravel-mailjet/releases/tag/1.1.1 But the code within there seems to be referring to an outdated Laravel.

    opened by bldcaveman 8
  • Remove Tinker. Change version constraints.

    Remove Tinker. Change version constraints.

    I removed Tinker as it does not seem to be used at all. Right now it is only causing problems with installation on Laravel 6.x (#26). It also should fix previous issues from #18, #20.

    opened by TheDoctor0 7
  • Send link parameter for campaign template

    Send link parameter for campaign template

    I am trying to send a campaign template by its id in Laravel and in the template I have a button as a link, but I need to specify the link from Laravel. Could you please tell me if there is a way of doing this? Thanks in advance, Stefanija

    opened by StefanijaK 7
  • Question: New release for php 8 missing?

    Question: New release for php 8 missing?

    Hi!

    Looks like you guys already made the afford to make the code base working with php 8 - thanks for that!

    @uavn I can't find a release with a tag pointing to the latest changes - am I missing something here?

    Thanks in advance!

    Tim

    opened by fachcraftim 4
  • Fetching a non-existent contact results in breaking exception

    Fetching a non-existent contact results in breaking exception

    When using $result = Mailjet::get(Resources::$Contact, ['id'=>$user_email]); to fetch a non existent contact we get an exception that breaks the flow when instead it should just state the user doesn't exist otherwise we can't check before adding or deleting.

    opened by bldcaveman 4
  • Add support with Laravel 6.x

    Add support with Laravel 6.x

    Hi !

    Here the error message when i'm trying to install laravel-mailjet :

    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Can only install one of: laravel/tinker[1.x-dev, v2.1.0].
        - Can only install one of: laravel/tinker[v2.1.0, 1.x-dev].
        - Can only install one of: laravel/tinker[1.x-dev, v2.1.0].
        - mailjet/laravel-mailjet 2.1.0 requires laravel/tinker ~1.0 -> satisfiable by laravel/tinker[1.x-dev].
        - Installation request for mailjet/laravel-mailjet ^2.1 -> satisfiable by mailjet/laravel-mailjet[2.1.0].
        - Installation request for laravel/tinker (locked at v2.1.0, required as ^2.0) -> satisfiable by laravel/tinker[v2.1.0].
    

    for the moment i downgrade tinker with :

    "laravel/tinker": "^1",
    
    opened by deshiloh 3
  • How to add a contact to a list

    How to add a contact to a list

    Hi,

    I try to use this SDK and i'm doing this to add a contact in a list :

    use Mailjet\LaravelMailjet\Facades\Mailjet;
    
      $mj = Mailjet::getClient();
      $response =  $mj->createContact($body);
    

    I have this error

    Symfony\Component\Debug\Exception\FatalThrowableError
    Call to undefined method Mailjet\Client::createContact()
    

    How can i call the method createContact ? Thanks

    opened by djoo 3
  • Inline attachments don't work

    Inline attachments don't work

    Hi, using $message->embed($pathToFile); to embed an inline attached image, results in empty img tag on received email. Is there any workaround? Could you add inline attachment compatibility to this package?

    opened by dicaccamovincenzo92 0
  • User is not set.

    User is not set.

    Hi! I followed the guidelines, but i have this issue:

    User is not set

    image

    In my .env file, i have only this variable:

    MAIL_MAILER=mailjet
    MAILJET_APIKEY= [my api key]
    MAILJET_APISECRET= [my api secret key]
    [email protected]
    MAIL_FROM_NAME=NOUGATSSILVAIN
    

    In my mail.php file:

    'mailjet' => [
                'transport' => 'mailjet',
                'key' => env('MAILJET_APIKEY'),
                'secret' => env('MAILJET_APISECRET'),
                'transactional' => [
                    'call' => true,
                    'options' => [
                        'url' => 'api.mailjet.com',
                        'version' => 'v3.1',
                        'call' => true,
                        'secured' => true
                    ]
                ],
            ],
    

    In services.php :

    'mailjet' => [
            'key' => env('MAILJET_APIKEY'),
            'secret' => env('MAILJET_APISECRET'),
        ]
    

    And my route:

    Route::get('/email', function() {
    
        $messageBody = "TEST MESSAGE BODY";
        Mail::raw($messageBody, function($message) {
            $message->to('[email protected]', 'TEST')
                ->subject('TEST');
            $message->from('[email protected]','My name');
        });
    });
    

    What i'm doing wrong? Thanks a lot! Vincent

    opened by pit07 0
  • Reply-to addresses

    Reply-to addresses

    We’re using Mailjet as the driver for Statamic. Emails are sending perfectly but however we define the reply-to email address, they don’t seem to feed through – replying always prefills to the sender’s email address.

    We’ve used other drivers in the past where this functionality works. Is this something that can be set through this package? Or is it likely a configuration issue (either between laravel-mailjet and Statamic or at the account end)?

    opened by websmyth 0
  • Driver [mailjet] not supported

    Driver [mailjet] not supported

    Hi,

    I seem to have an issue using this package. As the title states, when sending mails using the Mailable transport I get the "Driver [mailjet] not supported" error-message.

    Here is my composer:

    {
        "name": "laravel/laravel",
        "type": "project",
        "description": "The Laravel Framework.",
        "keywords": [
            "framework",
            "laravel"
        ],
        "license": "MIT",
        "require": {
            "php": "^7.1.3",
            "aws/aws-sdk-php": "~3.0",
            "doctrine/dbal": "^2.9",
            "elic-dev/laravel-math-captcha": "^1.0",
            "erusev/parsedown": "^1.7",
            "fideloper/proxy": "^4.0",
            "jrm2k6/cloudder": "^0.6.0",
            "laravel/framework": "5.8.*",
            "laravel/telescope": "^2.0",
            "laravel/tinker": "^1.0",
            "mailjet/laravel-mailjet": "^3.0"
        },
        "require-dev": {
            "barryvdh/laravel-debugbar": "^3.2",
            "beyondcode/laravel-dump-server": "^1.0",
            "filp/whoops": "^2.0",
            "fzaninotto/faker": "^1.4",
            "laravel/telescope": "^2.0",
            "mockery/mockery": "^1.0",
            "nunomaduro/collision": "^3.0",
            "phpunit/phpunit": "^7.5"
        },
        "config": {
            "optimize-autoloader": true,
            "preferred-install": "dist",
            "sort-packages": true
        },
        "extra": {
            "laravel": {
                "dont-discover": []
            }
        },
        "autoload": {
            "psr-4": {
                "App\\": "app/"
            },
            "files": [
                "app/helpers.php"
            ],
            "classmap": [
                "database/seeds",
                "database/factories"
            ]
        },
        "autoload-dev": {
            "psr-4": {
                "Tests\\": "tests/"
            }
        },
        "minimum-stability": "dev",
        "prefer-stable": true,
        "scripts": {
            "post-autoload-dump": [
                "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
                "@php artisan package:discover --ansi"
            ],
            "post-root-package-install": [
                "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
            ],
            "post-create-project-cmd": [
                "@php artisan key:generate --ansi"
            ]
        }
    }
    

    I followed the instructions:

    • install using composer: composer require mailjet/laravel-mailjet
    • add provider
    • add alias
    • add the mailjet service in services.php
    • and added the env constants (in my case for Laravel 5.8, I used MAIL_DRIVER=mailjet)

    I then simply send it using the Mailable instance:

    Mail::to(config('mail.from.address'))->queue(new ContactFormMail($contact));

    <?php
    
    namespace App\Mail;
    
    use Illuminate\Bus\Queueable;
    use Illuminate\Mail\Mailable;
    use Illuminate\Queue\SerializesModels;
    
    class ContactFormMail extends Mailable
    {
        use Queueable, SerializesModels;
    
        protected $data;
    
        /**
         * Create a new message instance.
         *
         * @return void
         */
        public function __construct(array $data)
        {
            $this->data = $data;
        }
    
        /**
         * Build the message.
         *
         * @return $this
         */
        public function build()
        {
            return $this->from(config('mail.from.address'), "TEST")
                ->subject('Contact form submitted')
                ->markdown('frontend.mails.contact')
                ->with([
                    'name' => $this->data['name'],
                    'phone' => $this->data['phone'],
                    'email' => $this->data['email'],
                    'body' => $this->data['body'],
                    'ip' => $this->data['ip'],
                ]);
        }
    }
    

    Is there no support anymore for Laravel 5.8? Or am I missing something? Thanks in advance

    opened by pixeliner 3
  • Missing dependencies?

    Missing dependencies?

    It's kind of related to this one https://github.com/mailjet/laravel-mailjet/issues/53 .

    The issue I am seeing is that after the upgrade to 3.0.1, it breaks saying the following: You cannot use "Symfony\Component\Mailer\Transport\AbstractHttpTransport" as the HttpClient component is not installed. Try running "composer require symfony/http-client"

    Doing some research, looks like this package is not actually required as dependency, only if you use some specific mailer, maybe that's the case, I don't know. I can see this has been added on the require here: "symfony/mailjet-mailer": "^6.0" but maybe it is not enough.

    If I install the symfony/http-client package though, I get then a different error:

    "Swift_Mailer::__construct(): Argument #1 ($transport) must be of type Swift_Transport, Symfony\Component\Mailer\Bridge\Mailjet\Transport\MailjetApiTransport given, called in /var/www/vendor/laravel/framework/src/Illuminate/Mail/MailManager.php on line 152"

    do you think this is something you can help with?? (or am I completely lost :sweat_smile: ?)

    opened by FrancescJR 9
  • Using the Subject Line from a Template

    Using the Subject Line from a Template

    I am trying to use the subject line from my template in an email. The problem is, if you don't provide a subject line to a Laravel Mailable, the following code creates a subject line based on the classname.

    $message->subject(Str::title(Str::snake(class_basename($this), ' ')));

    In addition, setting the subject line to a "truthy" value, results in it overriding the subject line on the template. I haven't been able to find a way around this, but if one exists I'd appreciate some advice.

    opened by temp1029 1
Releases(3.0.3)
Owner
Mailjet
Mailjet's official Github account. One powerful API to deliver, process and analyze your email
Mailjet
Configure Magento 2 to send email using Google App, Gmail, Amazon Simple Email Service (SES), Microsoft Office365 and many other SMTP (Simple Mail Transfer Protocol) servers

Magento 2 SMTP Extension - Gmail, G Suite, Amazon SES, Office 365, Mailgun, SendGrid, Mandrill and other SMTP servers. For Magento 2.0.x, 2.1.x, 2.2.x

MagePal :: Magento Extensions 303 Oct 7, 2022
Laravel Blog Package. Easiest way to add a blog to your Laravel website. A package which adds wordpress functionality to your website and is compatible with laravel 8.

Laravel Blog Have you worked with Wordpress? Developers call this package wordpress-like laravel blog. Give our package a Star to support us ⭐ ?? Inst

Binshops 279 Dec 28, 2022
A Laravel Wrapper for the Binance API. Now easily connect and consume the Binance Public & Private API in your Laravel apps without any hassle.

This package provides a Laravel Wrapper for the Binance API and allows you to easily communicate with it. Important Note This package is in early deve

Moinuddin S. Khaja 7 Dec 7, 2022
Turkpin API With this package, you can create an epin order and deliver it to your customers

Turkpin API Package Turkpin API With this package, you can create an epin order and deliver it to your customers. Official Documentation Installation

ANILKEN 4 Dec 11, 2022
This package provides a simple and intuitive way to work on the Youtube Data API. It provides fluent interface to Youtube features.

Laravel Youtube Client This package provides a simple and intuitive way to work on the Youtube Data API. It provides fluent interface to Youtube featu

Tilson Mateus 6 May 31, 2023
A PHP API extension the 'An API of Ice and Fire'

This documentation is meant to enable you to consume our API and get you started right away using your favourite programming language. All endpoints and HTTP methods to be used have been detailed with a sample example for e

David Syengo 1 Mar 26, 2022
Simple Symfony API-Platform Template which you can use to start to develop with symfony and api-platform

symfony-api-platform-skeleton Simple Template for Symfony API You can fork it and change the git remote to your Repo git remote set-url <your-git-remo

null 1 Jan 23, 2022
PDF API. JSON to PDF. PDF Template Management, Visual HTML Template Editor and API to render PDFS by json data

PDF Template Management, Visual HTML Template Editor and API to render PDFS by json data PDF ENGINE VERSION: development: This is a prerelease version

Ajous Solutions 2 Dec 30, 2022
salah eddine bendyab 18 Aug 17, 2021
Traits used primarily in the v6 package but also available as a helper package for applications

Phalcon Traits This package contains traits with methods that are used for Phalcon v6 onward. It can also be useful to others that want short snippets

The Phalcon PHP Framework 5 Oct 7, 2022
This package is aimed to be a simplistic PHP workflow package that works in a similar fashion to GitHub Actions.

Workflow This package is aimed to be a simplistic PHP workflow package that works in a similar fashion to GitHub Actions. Installation To install this

Steve McDougall 4 Sep 26, 2022
Quick package/plugin/component (repo) lookup for your favourite package managers

Package Managers (Download latest release) Package Repo Search Quick package/plugin/component (repo) lookup for your favourite package managers.

will Farrell 689 Dec 27, 2022
The fastest way to make a powerful JSON:API compatible Rest API with Laravel.

The first fully customizable Laravel JSON:API builder. "CRUD" and protect your resources with 0 (zero) extra line of code. Installation You can instal

BinarCode 394 Dec 23, 2022
A PHP package to make the Chronopost API easier to use.

Chronopost API A PHP package to make the Chronopost API easier to use. Table of Contents Requirements Installation Usage Testing Requirements PHP 7.3,

HOUIS Mathis 9 Oct 27, 2022
A simple package for interacting with the exchangerate.host API

Table of Contents Overview Installation Usage Methods Exchange Rate Getting the Rate Between Two Currencies Getting the Rate Between More Than Two Cur

Ash Allen 23 Feb 16, 2022
A composer package designed to help you create a JSON:API in Phalcon

phalcon-json-api-package A composer package designed to help you create a JSON:API in Phalcon What happens when a PHP developer wants to create an API

Jim 36 Oct 7, 2022
Google Search Results PHP API via Serp Api

Google Search Results in PHP This Php API is meant to scrape and parse Google, Bing or Baidu results using SerpApi. The full documentation is availabl

SerpApi 42 Nov 14, 2022
Code to accompany the YouTube video "Full PHP cURL API tutorial - how to use a REST API from PHP using cURL"

PHP cURL CRUD Example Example code to accompany this YouTube video. Note that the init_curl.php file contains a placeholder for an API key. DO NOT che

Dave Hollingworth 14 Dec 24, 2022