This Twig extension allows you to easily create mailto: links in your templates.
Install the library with Composer:
composer require 1tomany/twig-mailto
Tag the OneToMany\Twig\MailtoExtension as a Twig extension in your services configuration:
services:
OneToMany\Twig\MailtoExtension:
tags: [twig.extension]This extension exposes a single function named mailto() with the following signature:
function mailto(string $email, string $subject = '', string $content = ''): string;In your Twig template, create a mailto: link by calling it like this:
<a href="{{ mailto('contact@example.com', 'I need help!', 'Please help me. Thank you!') }}">
Email us for help
</a>This will generate the following value:
mailto:contact@example.com?subject=I%20need%20help%21&body=Please%20help%20me.%20Thank%20you%21./vendor/bin/phpunitThe MIT License