今天在博客留言板上光光同学留下了一个消息更新博客链接,在收到后来的评论回复邮件通知的时候(使用Mail To Commenter插件)发现邮件通知的发件人名称显示为wordpess,发件人邮件地址为user@servername的形式而且显示出来是乱码。
以前曾对此进行过DIY并做了本地存档,因为刚升级了WP3.0.3以前的文件被覆盖了所以会出现此问题,今天就把过程顺手贴上来。
需要修改的文件为/wp-includes/pluggable.php,详情如下。
以Emeditor等支持编码并能区别UTF-8带/不带签名(BOM)的编辑器打开pluggable.php文件,搜索”making my life hard again”,下面:
- $from_name = substr( $content, 0, strpos( $content, ‘<‘ ) – 1 );
- $from_name = str_replace( ‘”‘, ”, $from_name );
- $from_name = trim( $from_name );
- $from_email = substr( $content, strpos( $content, ‘<‘ ) + 1 );
- $from_email = str_replace( ‘>’, ”, $from_email );
- $from_email = trim( $from_email );
- } else {
- $from_email = trim( $content );
- }
本段代码功能:从评论表单中收集用户昵称信息并删除其中的空格,用于通知博客管理员。发件人名称为评论用户昵称,发件人地址为wordpress@yourdomail. 在此将发件人地址自定义,替换为:
- $from_name = substr( $content, 0, strpos( $content, ‘<‘ ) – 1 );
- $from_name = str_replace( ‘”‘, ”, $from_name );
- $from_name = trim( $from_name );
- $from_email = ‘noreply@cfresh.net’;
- } else {
- $from_email = ‘noreply@cfresh.net’;
- }
如果需要将邮件中出现的发件人名称同样修改为自己的博客名称及其他自定义信息,则还需要修改”$from_name”值,替换代码如下:
- $from_name = ‘秋天博客’;
- $from_email = ‘noreply@cfresh.net’;
- } else {
- $from_email = ‘noreply@cfresh.net’;
- }
其中的”$from_name”值为博客名称,”$from_email”值为使用的自定义用于发送邮件的地址,根据自己的实际情况修改。
下一步:修改博客默认发件信息,往下搜索:”If we don’t have a name from the input headers”,将下面的:
- if ( !isset( $from_name ) )
- $from_name = ‘WordPress’;
- /* If we don’t have an email from the input headers default to wordpress@$sitename
- * Some hosts will block outgoing mail from this address if it doesn’t exist but
- * there’s no easy alternative. Defaulting to admin_email might appear to be another
- * option but some hosts may refuse to relay mail from an unknown domain. See
- * http://trac.wordpress.org/ticket/5007.
- */
- if ( !isset( $from_email ) ) {
- // Get the site domain and get rid of www.
- $sitename = strtolower( $_SERVER[‘SERVER_NAME’] );
- if ( substr( $sitename, 0, 4 ) == ‘www.’ ) {
- $sitename = substr( $sitename, 4 );
- }
- $from_email = ‘wordpress@’ . $sitename;
- }
- $from_email = ‘wordpress@’ . $sitename;
- }
替换为:
- if ( !isset( $from_name ) )
- $from_name = ‘秋天博客’;
- /* If we don’t have an email from the input headers default to wordpress@$sitename
- * Some hosts will block outgoing mail from this address if it doesn’t exist but
- * there’s no easy alternative. Defaulting to admin_email might appear to be another
- * option but some hosts may refuse to relay mail from an unknown domain. See
- * http://trac.wordpress.org/ticket/5007.
- */
- if ( !isset( $from_email ) ) {
- $from_email = ‘noreply@cfresh.net’;
- }
在$wp_email这个函数中,也有调用,搜索:”$wp_email= ‘wordpress@’“,将所在行:
- $wp_email= ‘wordpress@’ . preg_replace(‘#^www\.#’, ”, strtolower($_SERVER[‘SERVER_NAME’]));
替换为:
- $wp_email= ‘noreply@cfresh.net’;
至此,全部替换修改完成,接着是保存。由于 pluggable.php原文件使用的编码为GB2312简体中文,当修改后的信息中含有中文时如果直接保存会导致显示的$from_name即博客名称为乱码;如果保存为UTF-8带签名(UTF-8 有BOM)编码,则Wordpress后台登录后将变成空白。
故修改完成后,需将文件另存为编码为UTF-8不带签名(UTF-8 无BOM)的同名文件以覆盖原文件。
BTW:请大家近期不要将Askimet插件升级到最新的2.5.0版,因存在一个BUG:所有人包括管理员自己的评论都将需要审核(我遇到的情况是一边需要审核一边又能显示在前台),已经升级的解决办法是删除后重新下载启用2.4.0版,下载地址:http://downloads.wordpress.org/plugin/akismet.2.4.0.zip
转载请尊重版权,出处:秋天博客 本文链接: https://www.cfresh.net/pc-tech/860
Namecoin访问谷歌,推特,油管,海外游戏加速,就用vpn加速器,限时免费体验https://66chy.com/#/register?code=qRzpH9La