WordPress修改新用户注册邮件内容的方法
发布时间:2014-12-16 17:14:59 作者:佚名
我要评论
这篇文章主要为大家介绍了WordPress修改新用户注册邮件内容的方法,介绍了两种方法可实现针对注册邮箱内容的个性化修改,是比较实用的技巧,需要的朋友可以参考下
本文实例讲述了如何修改WordPress新用户注册邮件内容,因为系统发送的邮件是纯文本类型的,页面不太美观,又没有办法发送自定义的HTML格式的邮件,将修改方法分享给大家供大家参考。具体方法如下:
最简单的办法
方法一、直接手动修改:
修改wordpresswp-includes目录的pluggable.php,中的这段:
复制代码
代码如下:$message = sprintf(__('Username: %s'), $user_login) . "";
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "";
$message .= wp_login_url() . "";
wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "";
$message .= wp_login_url() . "";
wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
例如改为如下代码:
复制代码
代码如下:$message .= sprintf(__('欢迎加入***网')) . "rn";
$message .= sprintf(__('Username: %s'), $user_login) . "rn";
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "rn";
$message .= wp_login_url() . "rn";
$message .= sprintf(__('账号需进一步审核才可以登入,请通知网站管理员')) . "rn";
wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
$message .= sprintf(__('Username: %s'), $user_login) . "rn";
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "rn";
$message .= wp_login_url() . "rn";
$message .= sprintf(__('账号需进一步审核才可以登入,请通知网站管理员')) . "rn";
wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);
方法二:
我们在当前主题的functions.php中加入重新定义的wp_new_user_notification函数即可,下面是一个示例,可以根据自己的需求进行修改:
复制代码
代码如下:if ( !function_exists('wp_new_user_notification') ) :
/**
* Notify the blog admin of a new user, normally via email.
*
* @since 2.0
*
* @param int $user_id User ID
* @param string $plaintext_pass Optional. The user's plaintext password
*/
function wp_new_user_notification($user_id, $plaintext_pass = '') {
$user = get_userdata( $user_id );
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
// 获取博客名称
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
// 给管理员发送的邮件内容,这里是HTML格式
$message = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>新用户注册</title></head><body><div align="center"><table cellpadding="0" cellspacing="1" style="border:3px solid #d9e9f1;background:#7fbddd; text-align:left;"><tr><td style="padding:0;"><table cellpadding="30" cellspacing="0" style="border:1px solid #ffffff;background:#f7f7f7;width:500px;"><tr><td style="line-height:2;font-size:12px;">您的网站 <strong>' . $blogname . '</strong> 有新用户注册。
用户名:' . $user_login . '
Email:' . $user_email . '
如果您不是 <strong>' . $blogname . '</strong> 的管理员,请直接忽略本邮件!</div></td></tr></table></td></tr></table></div></body></html>';
// 给网站管理员发送邮件
$message_headers = "Content-Type: text/html; charset="utf-8"n";
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message, $message_headers);
if ( emptyempty($plaintext_pass) )
return;
// 你可以在此修改发送给新用户的通知Email,这里是HTML格式
$message = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>新用户注册</title></head><body><div align="center"><table cellpadding="0" cellspacing="1" style="border:3px solid #d9e9f1;background:#7fbddd; text-align:left;"><tr><td style="padding:0;"><table cellpadding="30" cellspacing="0" style="border:1px solid #ffffff;background:#f7f7f7;width:500px;"><tr><td style="line-height:2;font-size:12px;">您刚刚在网站 <strong>' . $blogname . '</strong> 注册一个帐号。
用户名:' . $user_login . '
登录密码:' . $plaintext_pass . '
登录网址:<a href="' . wp_login_url() . '">' . wp_login_url() . '</a>
如果您没有在 <strong>'. $blogname . '</strong> 注册过任何信息,请直接忽略本邮件!</div></td></tr></table></td></tr></table></div></body></html>';
// sprintf(__('[%s] Your username and password'), $blogname) 为邮件标题
wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message, $message_headers);
}
endif;
/**
* Notify the blog admin of a new user, normally via email.
*
* @since 2.0
*
* @param int $user_id User ID
* @param string $plaintext_pass Optional. The user's plaintext password
*/
function wp_new_user_notification($user_id, $plaintext_pass = '') {
$user = get_userdata( $user_id );
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
// 获取博客名称
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
// 给管理员发送的邮件内容,这里是HTML格式
$message = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>新用户注册</title></head><body><div align="center"><table cellpadding="0" cellspacing="1" style="border:3px solid #d9e9f1;background:#7fbddd; text-align:left;"><tr><td style="padding:0;"><table cellpadding="30" cellspacing="0" style="border:1px solid #ffffff;background:#f7f7f7;width:500px;"><tr><td style="line-height:2;font-size:12px;">您的网站 <strong>' . $blogname . '</strong> 有新用户注册。
用户名:' . $user_login . '
Email:' . $user_email . '
如果您不是 <strong>' . $blogname . '</strong> 的管理员,请直接忽略本邮件!</div></td></tr></table></td></tr></table></div></body></html>';
// 给网站管理员发送邮件
$message_headers = "Content-Type: text/html; charset="utf-8"n";
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message, $message_headers);
if ( emptyempty($plaintext_pass) )
return;
// 你可以在此修改发送给新用户的通知Email,这里是HTML格式
$message = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>新用户注册</title></head><body><div align="center"><table cellpadding="0" cellspacing="1" style="border:3px solid #d9e9f1;background:#7fbddd; text-align:left;"><tr><td style="padding:0;"><table cellpadding="30" cellspacing="0" style="border:1px solid #ffffff;background:#f7f7f7;width:500px;"><tr><td style="line-height:2;font-size:12px;">您刚刚在网站 <strong>' . $blogname . '</strong> 注册一个帐号。
用户名:' . $user_login . '
登录密码:' . $plaintext_pass . '
登录网址:<a href="' . wp_login_url() . '">' . wp_login_url() . '</a>
如果您没有在 <strong>'. $blogname . '</strong> 注册过任何信息,请直接忽略本邮件!</div></td></tr></table></td></tr></table></div></body></html>';
// sprintf(__('[%s] Your username and password'), $blogname) 为邮件标题
wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message, $message_headers);
}
endif;
中间的$message中的内容你自己爱怎么写就怎么写吧.
希望本文所述对大家的WordPress建站有所帮助。
相关文章
- 对于Wordpress,ItBuLu曾经也接触过一点点,因为不喜欢MYSQL的备份繁琐,不管是网站还是博客,都优先考虑ASP+ACC程序。2010-02-21
- 对于Wordpress,ItBuLu曾经也接触过一点点,因为不喜欢MYSQL的备份繁琐,不管是网站还是博客,都优先考虑ASP+ACC程序。2010-02-21
- wordpress回复评论文字想修改的童鞋们来看一下介绍啊2012-05-16
Wordpress(Wp)3.5版修改默认上传图片路径的解决方法
相信接触过WP系统的朋友都了解,老版系统的上传图片路径是默认指向wp-content目录下的。做过WP博客的朋友应该十分熟识后台的设置,以前的版本是在Settings修改媒体Media的2013-02-22修改wordpress上传临时目录解决wordpress无法安装插件包的方法
安装插件遇到问题:无法安装这个包。 PCLZIP_ERR_MISSING_FILE (-4) : Missing archive file ‘C:\WINDOWS\TEMP/frontier.tmp’ ,下面看解决方法2013-12-13- 这篇文章主要介绍了wordpress修改固定链接后301重定向的方法,需要的朋友可以参考下2014-04-22


最新评论