wordpress代码实现邮件美化-wordpress美化

前言

有时wordpress主题默认邮件样式是真的简陋,简陋的都不忍直视,感觉让人仿佛回到了WEB 1.0时代,于是就在网上找了一些教程和资源,避免让大家踩坑

邮件主要美化的内容有:

1.评论通过通知评论者

2.用户更新账户通知用户

3.用户账户被删除通知用户

4.后台登录失败时通知管理员

5.发布新文章后邮件通知已注册的用户 

效果

准备

下载我提供的源码
源码无了,自己百度吧

如上图,将notify.php放入你所使用的主题根目录下,在主题文件function.php末尾加入代码:include_once(‘notify.php’); 即可使用。

需要更改的地方主要有以下几点:

第一点,修改背景图片。把图片路径输入上去就好了 

第二点,修改邮件尾部广告图,广告图片支持gif,png,jpg格式

 

 

第三点,把新发布文章通知用户删除(这个也是因人而异,需要的可以不删除)

 

注意
function wp_login_failed_notify(){
    date_default_timezone_set('PRC');
    $admin_email = get_bloginfo('admin_email');
    $to = $admin_email;
    $subject = '【登录失败】有人使用了错误的用户名或密码登录' . get_bloginfo('name') . '!';
    $message =  emailheadertop . get_bloginfo('name') . '账户登录失败通知!'.emailheaderbot.'
            <div style="padding:0;font-weight:bold;color:#6e6e6e;font-size:16px">尊敬的管理员您好!</div>
            <p style="color: red;font-size:13px;line-height:24px;">' . get_bloginfo('name') . '有一条登录失败的记录产生,若登录操作不是您产生的,请及时注意网站安全!</p>
            <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-top:1px solid #eee;border-left:1px solid #eee;color:#6e6e6e;font-size:16px;font-weight:normal">
                <thead><tr><th colspan="2" style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;background:#f8f8f8;">失败信息如下</th></tr></thead>
                <tbody>
				    <tr>
                        <td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;width:100px">登录名</td>
                        <td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $_POST['log'] . '</td>
                    </tr>
                    <tr>
                        <td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center">尝试的密码</td>
                        <td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $_POST['pwd'] . '</td>
                    </tr>
				    <tr>
                        <td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;">登录时间</td>
                        <td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . date("Y-m-d H:i:s") . '</td>
                    </tr>  
				    <tr>
                        <td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;">登录IP</td>
                        <td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $_SERVER['REMOTE_ADDR'] . '</td>
                    </tr>               
                </tbody>
            </table>
            '.emailfooter;
    wp_mail( $to, $subject, $message, "Content-Type: text/html; charset=UTF-8" );
}
add_action('wp_login_failed', 'wp_login_failed_notify');
add_filter('logout_url', 'mk_logout_redirect_home', 10, 2);

上述代码中的$_POST['值']要和你登录表单里<input>标签的name属性相同

例:<input name='user'>

那么,$_POST['值']就改为$_POST['user'],不然给你这个管理员发的邮件中不显示错误登陆用户的信息!

本站部分文章资源来源于互联网,仅供学习交流,如若要商用,请购买正版!
若不听劝告,网友造成出现一切后果,与本站本人无关
本站有些资源未经测试,请注意网络安全,本站不对下载的资源造成的后果负责
免责声明
作者:昼白
转载请注明来源:https://www.2bcnm.com/2753.htm
THE END
分享
二维码
打赏
海报
wordpress代码实现邮件美化-wordpress美化
前言 有时wordpress主题默认邮件样式是真的简陋,简陋的都不忍直视,感觉让人仿佛回到了WEB 1.0时代,于是就在网上找了一些教程和资源,避免让大家踩坑 邮件主……
<<上一篇
下一篇>>
文章目录
关闭
目 录