茹初见 發表於 2023-11-2 00:00:00

WordPress修改新用户注册邮件内容的方法

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
本文实例讲述了如何修改WordPress新用户注册邮件内容,因为系统发送的邮件是纯文本类型的,页面不太美观,又没有办法发送自定义的HTML格式的邮件,将修改方法分享给大家供大家参考。具体方法如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
最简单的办法</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
方法一、直接手动修改:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
修改wordpresswp-includes目录的pluggable.php,中的这段:<br>
 </p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode7" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
$message = sprintf(__('Username: %s'), $user_login) . ""; <br>
$message .= sprintf(__('Password: %s'), $plaintext_pass) . ""; <br>
$message .= wp_login_url() . ""; <br>
wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>例如改为如下代码:</span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode8" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
$message .= sprintf(__('欢迎加入***网')) . "rn"; <br>
$message .= sprintf(__('Username: %s'), $user_login) . "rn"; <br>
$message .= sprintf(__('Password: %s'), $plaintext_pass) . "rn"; <br>
$message .= wp_login_url() . "rn"; <br>
$message .= sprintf(__('账号需进一步审核才可以登入,请通知网站管理员')) . "rn"; <br>
wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message);</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>方法二:</span>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
我们在当前主题的functions.php中加入重新定义的wp_new_user_notification函数即可,下面是一个示例,可以根据自己的需求进行修改:<br>
 </p>
<div style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div style="margin: 0px; padding: 0px; outline: none; float: right; line-height: 25.2px; font-size: 14px;">
<span style="line-height: 25.2px; cursor: pointer;"><u>复制代码</u></span>
</div>
代码如下:</div>
<div id="phpcode9" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
if ( !function_exists('wp_new_user_notification') ) : <br>
/** <br>
* Notify the blog admin of a new user, normally via email. <br>
* <br>
* @since 2.0 <br>
* <br>
* @param int $user_id User ID <br>
* @param string $plaintext_pass Optional. The user's plaintext password <br>
*/ <br>
function wp_new_user_notification($user_id, $plaintext_pass = '') { <br>
$user = get_userdata( $user_id ); <br>
$user_login = stripslashes($user-&gt;user_login); <br>
$user_email = stripslashes($user-&gt;user_email); <br>
// 获取博客名称 <br>
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); <br>
// 给管理员发送的邮件内容,这里是HTML格式 <br>
$message = '&lt;html&gt;&lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;&lt;title&gt;新用户注册&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;div align="center"&gt;&lt;table cellpadding="0" cellspacing="1" style="border:3px solid #d9e9f1;background:#7fbddd; text-align:left;"&gt;&lt;tr&gt;&lt;td style="padding:0;"&gt;&lt;table cellpadding="30" cellspacing="0" style="border:1px solid #ffffff;background:#f7f7f7;width:500px;"&gt;&lt;tr&gt;&lt;td style="line-height:2;font-size:12px;"&gt;您的网站 &lt;strong&gt;' . $blogname . '&lt;/strong&gt; 有新用户注册。<br>
用户名:' . $user_login . '<br>
Email:' . $user_email . '<br>
如果您不是 &lt;strong&gt;' . $blogname . '&lt;/strong&gt; 的管理员,请直接忽略本邮件!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;'; <br>
// 给网站管理员发送邮件 <br>
$message_headers = "Content-Type: text/html; charset="utf-8"n"; <br>
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message, $message_headers); <br>
if ( emptyempty($plaintext_pass) ) <br>
return; <br><br>
// 你可以在此修改发送给新用户的通知Email,这里是HTML格式 <br>
$message = '&lt;html&gt;&lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;&lt;title&gt;新用户注册&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;div align="center"&gt;&lt;table cellpadding="0" cellspacing="1" style="border:3px solid #d9e9f1;background:#7fbddd; text-align:left;"&gt;&lt;tr&gt;&lt;td style="padding:0;"&gt;&lt;table cellpadding="30" cellspacing="0" style="border:1px solid #ffffff;background:#f7f7f7;width:500px;"&gt;&lt;tr&gt;&lt;td style="line-height:2;font-size:12px;"&gt;您刚刚在网站 &lt;strong&gt;' . $blogname . '&lt;/strong&gt; 注册一个帐号。<br>
用户名:' . $user_login . '<br>
登录密码:' . $plaintext_pass . '<br>
登录网址:&lt;a href="' . wp_login_url() . '"&gt;' . wp_login_url() . '&lt;/a&gt;<br>
如果您没有在 &lt;strong&gt;'. $blogname . '&lt;/strong&gt; 注册过任何信息,请直接忽略本邮件!&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;'; <br>
// sprintf(__('[%s] Your username and password'), $blogname) 为邮件标题 <br>
wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message, $message_headers); <br>
} <br>
endif;</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>中间的$message中的内容你自己爱怎么写就怎么写吧.</span>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
希望本文所述对大家的WordPress建站有所帮助。</p>
頁: [1]
查看完整版本: WordPress修改新用户注册邮件内容的方法