soundasleep/html2text
Convert HTML to clean, readable plain text in PHP. soundasleep/html2text handles tags, links, images, and whitespace to produce email-friendly, human-readable output, with sensible defaults and options for tweaking formatting.
Str::markdown() or dedicated libraries like spatie/html-to-markdown if richer output is needed.php artisan html:to-text).composer require soundasleep/html2text).Mailable to auto-generate plaintext versions:
use Soundasleep\Html2Text\Html2Text;
$html = $message->htmlParts;
$text = (new Html2Text())->getText($html);
$message->withPlainText($text);
Str helpers for further formatting (e.g., Str::limit()).$this->assertEquals(
"Hello World",
(new Html2Text())->getText("<h1>Hello World</h1>")
);
// Example: Process 1000 emails in chunks
Email::chunk(100, function ($emails) {
foreach ($emails as $email) {
dispatch(new ConvertHtmlToText($email->html));
}
});
filter_var($html, FILTER_VALIDATE_HTML).set_time_limit() or chunk processing.How can I help you explore Laravel packages today?