Download the PHP package aridez/simple-mail-builder without Composer
On this page you can find all versions of the php package aridez/simple-mail-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aridez/simple-mail-builder
More information about aridez/simple-mail-builder
Files in aridez/simple-mail-builder
Package simple-mail-builder
Short Description A tool to easily create emails in Laravel using a fluent interface
License MIT
Informations about the package simple-mail-builder
Simple Mail Builder
A tool to easily create emails in Laravel using a fluent interface.
Table of Contents
- Simple Mail Builder
- Table of Contents
- Installation
- Usage
- Basic Usage
- Quick reference
- Creating new components
- Creating a new theme
- Passing additional data
- Contributing
- Other
Installation
You can install the package via composer:
If you want to customize the mail views, you can publish them running:
Usage
Basic Usage
To start using the package, you need to create an instance of MailMessageBuilder
or just use the Mailbuilder
facade. Here's a basic example of how to use the package within a Laravel notification:
This code will create an email that looks like this:
Quick reference
The MailMessageBuilder
class provides several methods to add components and pass data to your views:
Method | Description |
---|---|
brand(string $image_url) |
Insert a brand image component. |
title(string $title) |
Insert a title component. |
text(string $text) |
Insert a plain text component. |
button(string $button_text, string $button_url) |
Insert a clickable button component. |
link(string $link_text, string $link_url) |
Insert a clickable link component. |
italic(string $text) |
Insert a grey italic text component. |
space(int $height) |
Insert vertical space component. |
theme(string $theme) |
Change the theme of the email view. |
component(string $name, array $props = []) |
Insert an arbitrary component with props. |
include(array $data) |
Append an array of top-level data. |
Creating new components
You can customize your views by creating or modifying the default theme of this package. First, publish the views as seen in the installation section. This makes them available under the folder resources\views\vendow\mailbuilder\components\themes\default
.
In order to create a component, just create a new blade file under that directory. You can take another of the default theme components as an example. Let's create a small text component called small-text.blade.php
:
Now, we will be able to use this component by calling the function component. The first parameter is a string that must be the name of the view (in this case small-text
) and the second is a key => value array where the keys must be the same as the props defined in our component:
Creating a new theme
To create a new whole custom theme, just create a new folder under resources\views\vendor\mailbuilder\components\themes
with the name of the theme you want to use and modify there the files accordingly:
resources/views/vendor/mailbuilder/components/themes
│
├── default
│ ├── brand.md
│ ├── title.md
│ ├── text.md
│ ├── button.md
│ ├── link.md
│ ├── italic.md
│ └── space.md
│
├── blue
│ ├── brand.md
│ ├── title.md
│ ├── text.md
│ ├── button.md
│ ├── link.md
│ ├── italic.md
│ └── space.md
Whenever you create a new theme, it is important to use the index.blade.php
as an entry point and also include the following lines where you will want to insert the parametrized components:
These lines are in charge of calling, rendering and passing any props to the corresponding view. You can take a look at the index.blade.php
file as an example.
Finally, to use a different theme you can call the theme function passing the name of the theme as a parameter:
Passing additional data
Sometimes, you will also want to pass additional data accessible from your index.blade.php
component, for example for headers or footers. For those cases you can use the include function and pass a key => value array that will get passed normally to your view. For example, if we want to access a $footer
variable from our index component we can do:
📝 Note: Make sure to avoid using the
components
key since it is reserved to render the array of components
Contributing
Contributions are welcome! Please follow these guidelines:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Make your changes.
- Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature/your-feature
). - Create a new Pull Request.
To prepare the development environment, you need to add it to your Laravel application. Developing locally, you can create a local repository. In your Laravel project's composer.json
, add the local repository path:
Then you can require the package normally:
Other
- Responsive email templates by ckissi