Skip to content

The package enhances the builtin Laravel Mailgun driver adding options like tracking opens, clicks and tagging emails

License

Notifications You must be signed in to change notification settings

ptejada/laravel-mailgun-options

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Mailgun Options Packagist

The package enhances the builtin Laravel Mailgun driver with helpers to manage the Mailgun specific features in a per email message basis. The following options can be configures with the helper:

  1. Toggle tracking email opens.
  2. Toggle tracking email link clicks.
  3. Add email tags.
  4. Attach variables and recipient variables to email.
  5. Enable test mode.
  6. Schedule email to be delivery in the future.

Refer to the Send via SMTP section of the Mailgun API docs for more information.

Installation

Install package via composer

composer require ptejada/laravel-mailgun-options

Compatibility

The package is tested and should be compatible with the following PHP and Laravel versions

PHP Laravel
7.3 7.x
7.4 7.x, 8.x
8.0 7.x, 8.x, 9.x
8.1 8.x, 9.x

Usage

Add the PabloTejada\MailgunOptions\MailgunOptions trait to any mailable class you want to configure. Within the build method of the mailable you can configure the Mailgun options using the following helpers:

  • track() - Track both email opens and clicks.
  • trackClicks() - Track when links in the email ar clicked.
  • trackOpens() - Track when the email is opened.
  • deliverBy() - Schedules the email to be deliver at a later time.
  • testMode() - Sends the email in test mode.
  • tags() - Adds one or more tags to the email.
  • variables - Attach variables to the email.
  • recipientVariables - Attach recipient specific variables to the email.
  • dkimSignature - Toggles the DKIM signatures.

Example mailable class

<?php

namespace App\Email;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use PabloTejada\MailgunOptions\MailgunOptions;

class EmailNotification extends Mailable
{
    use Queueable, SerializesModels, MailgunOptions;

    /**
     * @return EmailNotification
     */
    public function build()
    {
        $this->to('pablo@tejada.dev', 'Pablo Tejada');
        
        // Track email opens and clicks
        $this->track();
        
        // Add email tag or campaign    
        $this->tags('Test Campaign');
        
        // Enables the test mode if the app is not in production
        if ( ! app()->environement('production') ) {
        	$this->testMode();
        }

        return $this->markdown('email');
    }    
}

License

Laravel Mailgun Options is open-source software licensed under the MIT license.

About

The package enhances the builtin Laravel Mailgun driver adding options like tracking opens, clicks and tagging emails

Resources

License

Stars

Watchers

Forks

Packages

No packages published