PHPackages                             tobento/app-mail - 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. tobento/app-mail

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

tobento/app-mail
================

App mail support.

2.0.1(5mo ago)0795MITPHPPHP &gt;=8.4

Since Dec 1Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/tobento-ch/app-mail)[ Packagist](https://packagist.org/packages/tobento/app-mail)[ Docs](https://www.tobento.ch)[ RSS](/packages/tobento-app-mail/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (6)Dependencies (10)Versions (8)Used By (5)

App Mail
========

[](#app-mail)

Mail support for the app using the [Mail Service](https://github.com/tobento-ch/service-mail).

Table of Contents
-----------------

[](#table-of-contents)

- [Getting Started](#getting-started)
    - [Requirements](#requirements)
- [Documentation](#documentation)
    - [App](#app)
    - [Mail Boot](#mail-boot)
        - [Mail Config](#mail-config)
        - [Creating And Sending Messages](#creating-and-sending-messages)
        - [Message Templating](#message-templating)
            - [Writing Views Using The Mail CSS](#writing-views-using-the-mail-css)
            - [Templated Message](#templated-message)
        - [Queuing Messages](#queuing-messages)
- [Credits](#credits)

---

Getting Started
===============

[](#getting-started)

Add the latest version of the app mail project running this command.

```
composer require tobento/app-mail

```

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

[](#requirements)

- PHP 8.4 or greater

Documentation
=============

[](#documentation)

App
---

[](#app)

Check out the [**App Skeleton**](https://github.com/tobento-ch/app-skeleton) if you are using the skeleton.

You may also check out the [**App**](https://github.com/tobento-ch/app) to learn more about the app in general.

Mail Boot
---------

[](#mail-boot)

The mail boot does the following:

- installs and loads mail config file
- implements mail interfaces

```
use Tobento\App\AppFactory;
use Tobento\Service\Mail\MailerInterface;
use Tobento\Service\Mail\MailersInterface;
use Tobento\Service\Mail\RendererInterface;
use Tobento\Service\Mail\MessageFactoryInterface;
use Tobento\Service\Mail\QueueHandlerInterface;
use Tobento\Service\Mail\Symfony\EmailFactoryInterface;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots
$app->boot(\Tobento\App\Mail\Boot\Mail::class);
$app->booting();

// Implemented interfaces:
$mailer = $app->get(MailerInterface::class);
$mailers = $app->get(MailersInterface::class);
$renderer = $app->get(RendererInterface::class);
$messageFactory = $app->get(MessageFactoryInterface::class);
$queueHandler = $app->get(QueueHandlerInterface::class);
$emailFactory = $app->get(EmailFactoryInterface::class);

// Run the app
$app->run();
```

### Mail Config

[](#mail-config)

The configuration for the mail is located in the `app/config/mail.php` file at the default [**App Skeleton**](https://github.com/tobento-ch/app-skeleton) config location where you can specify the mailers for your application.

### Creating And Sending Messages

[](#creating-and-sending-messages)

```
use Tobento\Service\Mail\MailerInterface;
use Tobento\Service\Mail\Message;

class SomeService
{
    public function send(MailerInterface $mailer): void
    {
        $message = new Message()
            // you may set a from address overwriting
            // the defaults defined in the mail config file
            ->from('from@example.com')

            ->to('to@example.com')
            //->cc('cc@example.com')
            //->bcc('bcc@example.com')
            //->replyTo('replyto@example.com')
            ->subject('Subject')
            //->textTemplate('welcome-text')
            //->htmlTemplate('welcome')
            //->text('Lorem Ipsum')
            ->html('Lorem Ipsum');

        $mailer->send($message);
    }
}
```

Check out the [Mail Service - Creating And Sending Messages](https://github.com/tobento-ch/service-mail#creating-and-sending-messages) section to learn more about it.

### Message Templating

[](#message-templating)

The [Mail Boot](#mail-boot) automatically boots the [App View Boot](https://github.com/tobento-ch/app-view#view-boot) to support message templates out of the box.

Read more about general templating in the [Mail Service - Templating](https://github.com/tobento-ch/service-mail#templating) section.

#### Writing Views Using The Mail CSS

[](#writing-views-using-the-mail-css)

You may use the provided `mail.css` to quickly write simple formatted content views. The mail.css is actually the same as the [basis.css](https://docs.tobento.ch/css-basis) except being adjusted for HTML emails.

**Example Using The Content Class**

```
DOCTYPE html>
