您的位置:首页
WordPress改动新用户注冊邮件内容--自己定义插件
2017-07-04 10:53
369 查看
有些开放用户注冊功能的WordPress站点,可能有这么一项需求,就是用户注冊成功后,系统会分别给站点管理员和新用户发送一封通知邮件。给管理员发送的是新用户的username和Email,给刚刚注冊的新用户发送的是他的username和password。系统发送的邮件是纯文本类型的,页面不太美观,有没有办法发送自己定义的HTML格式的邮件呢?答案是能够的。
WordPress给我们提供了一个可供插件又一次定义的新用户邮件通知函数
wp_new_user_notification(),假设你不喜欢这个函数发送的邮件。我们能够又一次定义这个函数的内容,以达到我们自己定义的需求。
以上代码仅仅是一个演示样例,能够依据自己的需求进行改动。至于HTML邮件该怎么写,什么样的邮件格式美丽。这些就自己琢磨吧。
WordPress给我们提供了一个可供插件又一次定义的新用户邮件通知函数
wp_new_user_notification(),假设你不喜欢这个函数发送的邮件。我们能够又一次定义这个函数的内容,以达到我们自己定义的需求。
原函数
WordPress定义的这个函数内容是这样子的: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); // The blogname option is escaped with esc_html on the way into the database in sanitize_option // we want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $message = sprintf(__('New user registration on your site %s:'), $blogname) . "\r\n\r\n"; $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n"; $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n"; @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message); if ( empty($plaintext_pass) ) return; $message = sprintf(__('Username: %s'), $user_login) . "\r\n"; $message .= sprintf(__('Password: %s'), $plaintext_pass) . "\r\n"; $message .= wp_login_url() . "\r\n"; wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message); } endif;
自己定义邮件内容和格式
我们能够新建一个"插件",又一次定义的wp_new_user_notification函数定义的邮件内容就可以。我们在wp-content/plugins/文件夹下。新建一个文本文件命名为new-user-notification.php,插入下面代码。保存。然后在后台启动插件new-user-notification就可以:<?php /* Plugin Name: new-user-notification Description:又一次定义发送邮件的内容和格式 Version: 1.0 */ 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> 有新用户注冊。<br />用户名:' . $user_login . '<br />Email:' . $user_email . '<br /><br />假设您不是 <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 ( empty($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> 注冊一个帐号。<br />用户名:' . $user_login . '<br />登陆password:' . $plaintext_pass . '<br />登录网址:<a href="' . wp_login_url() . '">' . wp_login_url() . '</a><br /><br />假设您没有在 <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; ? >
以上代码仅仅是一个演示样例,能够依据自己的需求进行改动。至于HTML邮件该怎么写,什么样的邮件格式美丽。这些就自己琢磨吧。
相关文章推荐
- WordPress修改新用户注册邮件内容--自定义插件
- 怎样利用WordPress创建自己定义注冊表单插件
- WordPress修改新用户注册邮件内容
- WordPress无插件实现SMTP给评论用户发送邮件提醒
- 自己写插件实现wordpress评论回复邮件通知
- 在WordPress中注册新用户时无法收到确认邮件的问题
- Oracle 存储过程中发送邮件,并支持用户验证、中文标题和内容
- IIS+PHP下修改WordPress默认发送邮件方式为SMTP(免插件)
- 还原Wss3.0内容数据库时遇到:"ComputerName\Microsoft##SSEE 上的 WSS_Content 包含用户定义的架构。数据库在能够使用之前必须为空。请删除所有表、存储过程以及其他对象,或使用其他数据库。 " 的提示,无法加载内容数据库
- SAE平台搭建wordpress实现注册用户发送邮件
- 提高对邮件的认识,两类邮件都要重视!!(不光有和客户的邮件工作方面的,还有单位的邮件一些联系事项),还有要自己看清楚邮件的全部内容,不要丢三落四!!
- 做英文网赚的福音 wordpress 插件 文章内容生成器
- 而且用户可以自己定义关键词br 这
- 分享一个jQuery的自动客户端本地保存插件Sisyphus.js - 帮助你自动保存用户输入内容
- 分享一个jQuery的自动客户端本地保存插件Sisyphus.js - 帮助你自动保存用户输入内容
- 谷歌推出Chrome新插件 用户可屏蔽劣质内容(图)
- 在金笛邮件中设置让用户自己注册
- 插件和代码两种方法搞定WordPress回复邮件通知
- 自己写的jQuery插件(一)--让Iframe自适应内容高度
- WordPress自定义用户注册页面插件