Giter VIP home page Giter VIP logo

mail-bundle's Introduction

Mail bundle

Check on packagist MIT License

Watch on GitHub Star on GitHub Tweet

Why is this bundle here

In every project i need to build a way to send emails. Now symfony has released the Mime Component and the Mailer Component. Lets see what we can do to make live easier for us people who send emails.

Instalation

composer require disjfa/mail-bundle

Setup the interface

Setup the routes in config/routes/disjfa_mail.yaml. Here you can edit emails setup in your application.

disjfa_mail:
    resource: '@DisjfaMailBundle/Controller/'
    type: annotation
    prefix: '/admin'

Make you own template

Create a class that extends the MailInterface. Implement the name, subject and content as you want. You can inject the Translator to add simple translations or the twig Environment to render out templates.

<?php
namespace Disjfa\MailBundle\Mail;

interface MailInterface
{
    public function getName();
    public function getSubject();
    public function getContent();
}

In your templates there should be no twig variables. Escape those, like this: {{ '{{' }} email {{ '}}' }}. All the variables used are parsed and collected. The original variables are the only ones that should be used.

If you made a class it will be autoload in the MailCollection collection. And so editable if you have set up some routes for the interface.

Sending emails

Next up is sending emails. In your code just make a message or function that sets up the email.

use Disjfa\MailBundle\Mail\MailFactory;
use Disjfa\MailBundle\Mail\MailService;

function myFunction(MailFactory $mailFactory, MailService $mailService)
{
    $mail = $mailFactory->findByName('name');
    $mailService->send($mail, [
         'param1' => 'value',
         'param2' => 'value',
    ], '[email protected]');
}

And done! Mail sent. Now it is time to setup emails and make more in your application.

Extend the templates

You can manage the templates as is. But you probably want to integrate the files in your own system. Just create a file in your application in templates/bundles/DisjfaMailBundle/layout.html.twig and add a body block.

<!doctype html>
<html>
<head>
...
</head>
<body>
{% block body %}

{% endblock %}
</body>
</html>

And you are good to go. Or you can just extend your own template. Just make sure you use a block named body. You can also just extend the rest of the files as you wish. Just name them like we set up the files.

One thing missing

One thing missing is sending the emails. We do not have to set up the mailing bit of the application. You can do that yourself. Check the transports on how to set up your own mailer as you wish.

And that is about it.

Now you can make your own emails. Set them up. Create a method to send emails. And when you have set up your favorite mailer you can send them!

Help

This bundle is a nice way to extend your workflow. But it can be improved. If you have any ideas or solutions to do so don't be shy and tell us! We can only make stuff better in the end.

Enjoy!

Use the bundle. Check what the bundle does. Fork. Make your own. This is here just to make live easier for us all. Make something beautiful.

mail-bundle's People

Contributors

disjfa avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.