PHPackages                             twindots/email-service - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. twindots/email-service

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

twindots/email-service
======================

Compile shortcodes and send emails from predefined templates.

v1.2.0(4y ago)1136PHP

Since Feb 22Pushed 4y ago2 watchersCompare

[ Source](https://github.com/TwinDots/email-service)[ Packagist](https://packagist.org/packages/twindots/email-service)[ RSS](/packages/twindots-email-service/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (4)Used By (0)

Email service plugin for laravel 5|6|7|8
========================================

[](#email-service-plugin-for-laravel-5678)

This package simplify compiling shortcodes and sending emails.

Requirements
------------

[](#requirements)

- [PHP &gt;= 7.0](http://php.net/)
- [Laravel &gt;=5.x](https://github.com/laravel/framework)

Installation
------------

[](#installation)

**Install this package with composer:**

```
$ composer require twindots/email-service
```

Service Provider &amp; Facade will be discovered automatically by laravel. **Publish the config file and views folder:** *(required)*

```
$ php artisan vendor:publish --provider="TwinDots\EmailService\EmailServiceProvider"
```

This will publish the following:

- config/email\_service.php
- views/email\_service/views.blade.php
- views/email\_service/layout.blade.php
- views/email\_service/partials/

Usage
-----

[](#usage)

This package consist of 2 classes: EmailService and EmailShortCodes.

### 1- EmailShortCodes:

[](#1--emailshortcodes)

- Import the library:

```
   use EmailShortCodes;
```

- Load it in your function:

```
   public function compileCodes( EmailShortCodes $shortcodes )
   {
      // Or create a new instance
      // $shortcodes = new EmailShortCodes();

      $compiled = $shortcodes->objects([
                  'user' => $user,
               ])
               ->withUser()
               ->body( request('body') )
               ->compile();
   }
```

### 2- EmailService:

[](#2--emailservice)

- Import the library:

```
   use EmailService;
```

- Load it in your function:

```
   public function sendEmail( EmailService $emailService )
   {
      // Or create a new instance
      // $emailService = new EmailService();

      $result = $emailService->email(['email1@example.com', 'email2@example.com'])
                  ->subject( $subject )
                  ->body( $compiled ) // Send the compiled body or any html
                  ->attach([
                     'file-1.png' => 'path/to/file-1.png',
                     'file-2.pdf' => 'path/to/file-2.png'
                  ])
                  ->send();
   }
```

- this library will use the file **email\_service/view.blade** for the email template, you can change it from the config file.
- The `send()` function will return a result array having:
    - status (boolean): **True** for success and **false** for failed delivery.
    - Message (text) : Show the message of a failed delivery.

Shortcodes
----------

[](#shortcodes)

Shortcodes are defined inside the config file **config/email\_service.php** under the **shortcodes** array. You can define shortcodes inside groups in order to load each group for different email templates.

```
   'group_name' => [
     'short_code_1' => [...],
     'short_code_2' => [...],
   ]
```

Shortcodes can be inserted in your favorite text editor with this command:

```
 {shortcode_unique_name}

```

**P.S: This library will compile anything inside {}**

You can add 3 types of shortcodes:

- **Variable**:

```
  'user_first_name' => [        // shortcode unique name
     'title' => 'First name',   // shortcode friendly name
     'type' => 'variable',      // type is variable
     'object' => 'user',        // object can be any class, ex: $user
     'param' => 'first_name'    // parameter, ex first_name: $user->first_name
  ],
```

- **Function**:

```
  'user_full_name' => [        // shortcode unique name
     'title' => 'Full name',   // shortcode friendly name
     'type' => 'function',     // type is function
     'object' => 'user',       // object can be any class, ex: $user
     'param' => 'getFullName'  // parameter, ex: getFullName: $user->getFullName()
  ],
```

- **Blade view**:

```
  'user_image' => [                      // shortcode unique name
     'title' => 'User image',            // shortcode friendly name
     'type' => 'view',                   // type is view
     'object' => 'users.profile-image',  // object is the view path
  ],
```

For the blade view shortcode, you don't need to pass any objects since it will inherit the objects passed from the `$shortcodes->objects()` function.

### How to check which objects are required:

[](#how-to-check-which-objects-are-required)

If you are working with a large list of shortcodes inside a template with multiple variables and views, you need to know what are the required objects, simply call for the function `$shortcodes->objectsNeeded()`, it will return an array that will tell you what objects are needed.

Reference
---------

[](#reference)

### EmailShortCodes

[](#emailshortcodes)

MethodsParametersDefinitioncompile()-Will compile the **body** using the **shortcodes** list and **objects**body()String $bodySet the bodyobjects()Array $objectsSet the objectsgroup()String $groupSet the groupaddGroup()String $groupAdd a new group to the group listwithUser()-Add the user shortcode group to the shortcodes listgetGroup()-Return the groupshortcodes()-Return the shortcodes listobjectsNeeded()-Return the objects needed to compile### EmailService

[](#emailservice)

MethodsParametersDefinitionemail()Array,String $emailSet the recipient emailreplyTo()String $replyToSet replyTo, will override the value in config.mail.reply\_tocc()Array,String $ccSet ccbcc()Array,String $bccSet bccbody()String $bodySet the bodysubject()String $subjectSet the subjectattach()Array $attachmentsSet the attachmentssend()-Send the emailLicense
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/.../blob/master/LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~231 days

Total

3

Last Release

1815d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f2f1e5e9145b7e4ca91b33771bf0025cd84fe279907664761825fef55304d84?d=identicon)[AllenTwinDots](/maintainers/AllenTwinDots)

---

Top Contributors

[![AllenTwinDots](https://avatars.githubusercontent.com/u/61347570?v=4)](https://github.com/AllenTwinDots "AllenTwinDots (3 commits)")[![alainkhoury](https://avatars.githubusercontent.com/u/12054605?v=4)](https://github.com/alainkhoury "alainkhoury (2 commits)")

### Embed Badge

![Health badge](/badges/twindots-email-service/health.svg)

```
[![Health](https://phpackages.com/badges/twindots-email-service/health.svg)](https://phpackages.com/packages/twindots-email-service)
```

###  Alternatives

[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)[eduardokum/laravel-mail-auto-embed

Library for embed images in emails automatically

1702.0M5](/packages/eduardokum-laravel-mail-auto-embed)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
