cover-img

Automatically generate plain text e-mails without view in Laravel 5+

12 July, 2022

7

7

0

Plain text emails are still very important these days. For many of them, however, it is pointless to write a plain text version as long as it can be automatically generated from HTML format.

1. Install html2text package:


2. Create file TextMailBuilder.php:

This trait contains a buildView method that overwrites the original method and will generate text for the email only if you do not use your own view for the plain text version of the email.

Create Traits folder in app/Mails, then create TextMailBuilder.php file, then place the entire code to this file:


3. Import TextMailBuilder trait to your Mailables:

tutorial

php

laravel

automation

7

7

0

tutorial

php

laravel

automation

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2025. Showcase Creators Inc. All rights reserved.