现在发邮件怎么是这样,一点样式都没有了?
收到的评论通知邮件是纯文本 + 裸 URL,没有任何样式:
您的文章《留言本》有新评论 作者:BroMikey(IP 地址:211.64.159.175,...) 邮箱:... URL:... 评论:... 您可以在此看到该文章的所有评论:https://... 固定链接:https://... 移至回收站:https://... 标记为垃圾评论:https://...
theme-mail.php 的 yang_mail_normalize_headers() 把 Content-Type 强改成 text/html; charset=UTF-8,同时只接管了通道(SMTP / From / 编码)。 但正文仍是 WordPress 核心 wp_notify_postauthor() / wp_notify_moderator() 拼出来的纯文本。
theme-mail.php
yang_mail_normalize_headers()
Content-Type
text/html; charset=UTF-8
wp_notify_postauthor()
wp_notify_moderator()
声明成 HTML 却塞纯文本 ⇒ 客户端按 HTML 渲染,换行全丢、链接变裸地址。
为什么长期没暴露:yang_mail_disable_core_notify() 只在 wpDiscuz 在场时 拦截核心通知。插件在时,正文由 wpdiscuz_email_content 过滤器重渲染, 核心那段纯文本根本走不到。卸载 wpDiscuz 后,这条路径才第一次暴露。
yang_mail_disable_core_notify()
wpdiscuz_email_content
新增 inc/theme-mail-core.php,挂核心自己提供的两个过滤器:
inc/theme-mail-core.php
comment_notification_text
comment_moderation_text
不改核心文件。 wp-includes/pluggable.php 那两行 apply_filters() 是核心 自己写的扩展点,我们只是挂上去。删掉本文件立刻回到核心原始行为。
wp-includes/pluggable.php
apply_filters()
边界:
yang_mail_smtp_ready()
模板新增 links 参数,把「通过审核 / 移至回收站 / 标记为垃圾」渲染成一行 文字链接,而非并排按钮 —— 手机宽度下三个按钮必然换行、高度不齐。
links
渲染层:
apply_filters('comment_notification_text', 'PLACEHOLDER', 39436) len_in=23 len_out=10792 untouched=no has_table=yes has_trash=yes has_comment_text=yes apply_filters('comment_moderation_text', 'PLACEHOLDER', 39436) len_out=11090 has_approve=yes has_spam=yes
真实发信:wp_mail('i@yangyq.net', ...) → sent=yes
wp_mail('i@yangyq.net', ...)
sent=yes
发布链路:
update.json → version 4.2.2, md5 22a797c5... zip 可达 → code=200 size=4927535 后台检测 → new_version: 4.2.2 站点 → home=200
第一次直接在服务器上 scp 改了三个主题文件 —— 错了。用户指出 「应该放在更新里面让我更新」。已全部回滚到干净的 4.2.1,改为走正规流程:
改仓库 → git commit/push → 升 style.css → 打包 → 传 zip → 写 update.json → 后台更新
theme
id theme
theme_deploy.sh
btops
版本 4.2.2,线上更新已发布,等用户后台点更新。
inc/theme-mail-template.php
functions.php
style.css
commit:ec815d4(Windows 侧误用退役副本提交,内容与 WSL 同源,已验证 hash 一致)
ec815d4
# 渲染层 apply_filters('comment_notification_text','PLACEHOLDER',39436) → len 23 → 10792, has_table=yes, has_trash=yes, has_comment_text=yes apply_filters('comment_moderation_text','PLACEHOLDER',39436) → len 11090, has_approve=yes, has_spam=yes # 真实发信 wp_mail('i@yangyq.net', ...) → sent=yes # 发布链路 update.json → version 4.2.2, md5 22a797c5876b0cbfb3c6c523043ab856 zip HTTP → code=200, size=4927535 后台 transient → new_version: 4.2.2, package 指向 4.2.2.zip 站点首页 → 200
_trash_20261030/
git pull
theme-site
REPO=
checkForUpdates()
deploy/theme_deploy.sh
deploy/build_theme_zip.sh
D:/Yongquan/code/wordpress-kratos-yang
setup-theme-user.sh
No dependencies set.
The note is not visible to the blocked user.
用户原话(2026-11-06)
问题
收到的评论通知邮件是纯文本 + 裸 URL,没有任何样式:
根因(不是 SMTP,不是模板坏了)
theme-mail.php的yang_mail_normalize_headers()把Content-Type强改成text/html; charset=UTF-8,同时只接管了通道(SMTP / From / 编码)。但正文仍是 WordPress 核心
wp_notify_postauthor()/wp_notify_moderator()拼出来的纯文本。
声明成 HTML 却塞纯文本 ⇒ 客户端按 HTML 渲染,换行全丢、链接变裸地址。
为什么长期没暴露:
yang_mail_disable_core_notify()只在 wpDiscuz 在场时拦截核心通知。插件在时,正文由
wpdiscuz_email_content过滤器重渲染,核心那段纯文本根本走不到。卸载 wpDiscuz 后,这条路径才第一次暴露。
修复
新增
inc/theme-mail-core.php,挂核心自己提供的两个过滤器:comment_notification_text(有新评论 → 文章作者)comment_moderation_text(有待审评论 → 管理员)不改核心文件。
wp-includes/pluggable.php那两行apply_filters()是核心自己写的扩展点,我们只是挂上去。删掉本文件立刻回到核心原始行为。
边界:
yang_mail_smtp_ready()为真时接管(没配 SMTP 就放手,避免和别的邮件插件打架)模板新增
links参数,把「通过审核 / 移至回收站 / 标记为垃圾」渲染成一行文字链接,而非并排按钮 —— 手机宽度下三个按钮必然换行、高度不齐。
验证
渲染层:
真实发信:
wp_mail('i@yangyq.net', ...)→sent=yes发布链路:
流程纠正
第一次直接在服务器上 scp 改了三个主题文件 —— 错了。用户指出
「应该放在更新里面让我更新」。已全部回滚到干净的 4.2.1,改为走正规流程:
遗留
theme部署账号不存在(id theme→ no such user),theme_deploy.sh跑不通,本次用btops手动执行等效步骤。按记忆,该账号已于 2026-10-29 淘汰,脚本应改走
btops。已上线
版本 4.2.2,线上更新已发布,等用户后台点更新。
改了什么
inc/theme-mail-core.phpcomment_notification_text/comment_moderation_textinc/theme-mail-template.phplinks参数 → 一行文字链接functions.phpstyle.csscommit:
ec815d4(Windows 侧误用退役副本提交,内容与 WSL 同源,已验证 hash 一致)怎么验的
踩到的坑
_trash_20261030/)—— 铁律规定开发在 WSL。已把副本移回回收站,WSL 仓库
git pull到ec815d4并核验。theme-site别名失效 —— 不是配置丢失,theme用户 2026-10-29 已淘汰。theme_deploy.sh里的REPO=也还是 Windows 退役路径,脚本目前跑不通。需
checkForUpdates()强制刷新一次。遗留
deploy/theme_deploy.sh、deploy/build_theme_zip.sh的REPO=指向D:/Yongquan/code/wordpress-kratos-yang(已退役的 Windows 副本),且依赖不存在的
theme-site。这两个脚本需要改造成 WSL + btops 版本,目前靠手工等效步骤发版。另开工单处理。
setup-theme-user.sh与 README 里关于theme用户的说明已过期,建议清理。