钩子文档

wp_mail_charset

💡 云策文档标注

概述

wp_mail_charset 是一个 WordPress 过滤器,用于修改 wp_mail() 函数的默认字符集。默认字符集为 UTF-8,适用于多语言邮件发送,但开发者可通过此过滤器自定义字符编码。

关键要点

  • wp_mail_charset 过滤器允许修改 wp_mail() 的默认字符集,参数为 $charset 字符串。
  • 默认字符集为 UTF-8,推荐使用,因为它兼容 ASCII 并支持大多数语言。
  • 从 WordPress 3.5 版本起,字符集不再可从管理面板配置,固定为 UTF-8。
  • 此过滤器主要用于需要发送非 UTF-8 编码邮件的场景,如特定语言需求。

代码示例

add_filter( 'wp_mail_charset', 'change_mail_charset' );

function change_mail_charset( $charset ) {
    return 'UTF-32';
}

📄 原文内容

Filters the default wp_mail() charset.

Parameters

$charsetstring
Default email charset.

More Information

  • The default character encoding for wp_mail() is UTF-8. The character encoding can be changed using the wp_mail_charset filter.
  • While the average user is unlikely to need to change the default character encoding for email, users who need to send email in different languages may find this filter useful.
  • UTF-8 is still the recommended default character encoding to use since it’s backward compatible with ASCII and can represent nearly all languages. As a result, UTF-8 is the most ubiquitous character encoding being used on the web. Users/developers typically do not need to change the character encoding in order to read/write foreign langauges.
  • As of Version 3.5, WordPress character encoding is no longer configurable from the Administration Panel and defaults to UTF-8.

Source

$phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );

Changelog

Version Description
2.3.0 Introduced.

User Contributed Notes