Laravel provides us a facility to send email with custom html template. In order to achieve it, kindly follow the steps below:
1. Open your mail.php file from config folder and add these details:
2. After that open your gmail account and go to My Account -> Sign-in & Security. Find Allow less secure apps on that page and turn it on:
3. Create a new folder in view folder of your project name as email.
4. Create a new file as a email_template.blade.php in email folder.
5. Open this file and add custom template format to it. Like this:
You can add css as well in it. {!! $emailBody !!} , {{ $domainName }} are parameters which are passed through the controller function at the time of email sending. If you want to pass html tags with values to email template then use {!! !!} this instead of {{ }}.
In email sending function – Mail::send:
* First parameter is email template name with view name in which template is placed.
Like: ’email.email_template’
- But if you are passing html from controller to email template then use
[‘html’ => ’email.email_template’].
*Second parameter is email body
*Third one is message function with parameters like from, to, subject etc. :
On execution of the function, email is sent. Check the specified receiver’s email account, you will see an email like: