Hello everyone, welcome back to just laravel. Here am going to show you how you can send clean and beautiful HTML emails in your laravel applications using this Beauty mail package by SnowFire. In one of my previous post I showed you how to send emails using SendGrid mail service provider, here I extended to send a clean and elegant HTML emails rather than plain text emails.
Setting up Beautymail
So first pull this package into our application.
After composer finishes its installation, you need to add it to the service providers list in
Now you need to publish some of the assets provided by this package to the public folder,
Beautymail allows us to set some configurations for sending emails, where you can set logo to be sent in the email, its dimensions, and any social links to be included in you mail and all such settings.
You can change you settings in
View for entering email
I have made a simple app to show how this works, I place a input box, where one can enter an email address. Then that email address will be validate an will send a mail to that email address with our html email template we designed and customized.
So our view will look like,
It is basically a form with a single input for email adddress and a submit button for sending an email.
So when the submit button is pressed it goes to the route
sendmail where you can send an email, but before that I will design the view for the email to be sent.
Designing and customizing your email view
Beautymail provides us with few email templates to use, I use of them here and add some custom content to the view it provided. To see all the available templates, you can visit their GitHub repo: https://github.com/Snowfire/Beautymail.
I used ‘ark’ template, here is the example code they provided,
Here I removed the default hello world content and added some of post links and images and some text. You can add any content you want in between
Sending the mail
Firstly, to sen a mail you need to do some settings like setting up mailhost, username password and all. I used sengrid to send mail here. I also have a post covering how to get registered at send grid and send mails using it. Please look at that here.
In the form I set the action to
\sendMail, so I made a route for it,
In IndexController, I had a new function
In the above code, the following 2 lines sends a mail,
In the function message, you can add from address to address and subject for the mail.
After sending mail you can return to any success view or anything you wish, Here for the example sake, am just redirecting back.
I also added some validation for the email input, if you look at the initial lines of the function, I check the email for required and for a valid email case.
You can show the errors in the view, where ever you want by placing the following code,
The sent mail will look like the following,
Also my custom content I inserted will look like,
Also facebook and twitter icons in the footer,
That’s it for the post. Now you successfully know how to send beautiful emails from your laravel applications.
Please feel free to look at some of my previous post below,
- Vue Js and Laravel – CRUD Operations
- How to integrate PayPal payment gateway in Laravel
- How to use Middleware for content restriction based on user role
- How to send beautiful HTML emails with Laravel using Beauty mail
- Posts search and gallery view app in Vuejs