gbielbarbosa/react-email-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gbielbarbosa/react-email-php

最新稳定版本:1.0.0

Composer 安装命令:

composer require gbielbarbosa/react-email-php

包简介

A PHP library to parse Tiptap JSON from @resend/react-email editor into HTML

README 文档

README

Minimum PHP Version License

A PHP 8.1+ library designed to parse and render Tiptap JSON outputs generated by Resend React Email Editor into valid, email-safe HTML. It translates modern editor structures into cross-client compatible HTML tables.

Version Compatibility

This package processes JSON from the Resend React Email Editor. Please ensure you use compatible versions:

react-email-php @react-email/editor PHP Version
1.x.x ^1.0.0 >= 8.1

Installation

You can install the package via composer:

composer require gbielbarbosa/react-email-php

Usage

Converting JSON to Email-Safe HTML

To parse the JSON output from your front-end editor and render it as email-safe HTML, use the toHtml method. This method automatically handles layout components (Sections, Containers, Columns), mapping them to <table role="presentation"> tags to ensure Outlook, Apple Mail, and Gmail compatibility.

use ReactEmail\EmailParser;

$json = '{"type":"doc","content":[{"type":"body","content":[{"type":"container"}]}]}';

$parser = new EmailParser();
$html = $parser->toHtml($json);

echo $html;

The resulting $html will automatically include the proper HTML boilerplate (<!DOCTYPE>, <html>, <head>) if it's not present, and will dynamically inject any global styles defined in your editor's globalContent node.

Sanitizing JSON for Storage

Before saving the raw editor output to your database, you should sanitize it to prevent CSS/XSS injection payloads. The toJson method recursively traverses the JSON tree and strips invalid or malicious CSS values.

use ReactEmail\EmailParser;

// Raw JSON directly from the user's request
$rawJson = $_POST['editor_json'];

$parser = new EmailParser();
$safeJson = $parser->toJson($rawJson);

// $safeJson is now clean and ready to be stored in your database

Features

  • Pure PHP implementation.
  • Native rendering of complex layout components into responsive HTML tables.
  • Deep integration with the Tiptap structure.
  • Parses and injects global styles (from the globalContent node) directly into the corresponding body and container elements.

Supported Extensions

This library includes native support for the following Resend React Email Editor extensions:

  • Layout blocks: Body, Container, Section, Columns, ColumnsColumn, Div
  • Text elements: Heading, Paragraph, Blockquote, CodeBlock
  • Media & UI: Button, Img, Divider
  • Tables: Table, TableRow, TableCell, TableHeader
  • Lists: BulletList, OrderedList, ListItem
  • Inline Marks: Bold, Italic, Strike, Underline, Code, Sup, Uppercase, Link

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固