WordPress邮件回复样式,美化样式

 5年前     2K  

文章目录

WordPress邮件回复样式,美化样式

WordPress邮件回复美化样式,预览图,首先这不是我写的,这是我从搜索引擎上找的,我也不知道出自谁,互联网太繁杂,这里一为只做了小部分的修改,纯分享记录。

有新的模板发布,可以查看

如果你只要评论回复通知,可以用这篇文章的模板。

WordPress邮件回复样式,美化样式

我用的知更鸟主题,如果87行的zm_get_option('logo')方法你主题没有,请替换为自己主题的,也可以直接指定图片地址。

89行后面可以添加多个自定义菜单,如上图左上角”首页“按钮。

<?php 
if ( ! defined( 'ABSPATH' ) ) { exit; }
function comment_mail_notify($comment_id) {
  $comment = get_comment($comment_id);
  $parent_id = $comment->comment_parent ? $comment->comment_parent : '';
  $spam_confirmed = $comment->comment_approved;
  if (($parent_id != '') && ($spam_confirmed != 'spam')) {
  $wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME'])); //e-mail 发出点, no-reply 可改为可用的 e-mail.
  $to = trim(get_comment($parent_id)->comment_author_email);
  $subject = '您在 [' . get_option("blogname") . '] 的留言有了回复';
    $message = '
    <style>
        * {
            box-sizing: border-box;
        }
        body {
            font-family: "PingFang SC","Helvetica Neue","Helvetica","STHeitiSC-Light","Arial","Microsoft yahei","\005fae\008f6f\0096c5\009ed1",Verdana,sans-serif;
            font-weight: 400;
            font-size: 14px;
            line-height: 1.6;
            color: #333333;
            background: #f2f5f8;
        }
        a {
            color: #3292ff;
            text-decoration: none;
            border-bottom-style: dotted;
            border-bottom-width: 1px;
        }
        a:hover{
            text-decoration:none !important;
            border-bottom-style: solid;
        }
        h1,h2,h3,h4,h5,h6{
            font-weight: 500;
            line-height: 1.5;
            margin-bottom: 20px;
        }
        p {
            padding: 10px 0;
            /*margin: 0 20px;*/
            margin-bottom: 10px;
        }
        .btn {
            font-weight: 500;
            border-radius: 4px;
            padding: 16px 30px;
            text-align: center;
            background: #3885ff;
            text-decoration: none;
            color: #fff;
            margin: 15px auto;
            font-size: 16px;
            display: inline-block;
            border: none;
        }
        .btn:hover{
            border: none;
        }
        .btn-success {
            background: #2ecc71
        }
        blockquote {
            border-radius: 3px;
            background: #f5f5f5;
            margin: 10px 0;
            padding: 15px 20px;
            color: #455667;
        }
        .center{
            text-align: center;
        }
    </style>
    <div class="wrapper" style="margin:0;padding:0;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
        <tbody>
        <tr>
            <td class="inner" style="padding:30px 25px 40px 25px;background:#f2f5f8;" bgcolor="#f2f5f8" align="center">
                <table width="750" cellspacing="0" cellpadding="0" border="0">
                    <tbody>
                    <tr>
                        <td width="100%" style="border-radius:4px;background:#ffffff;" bgcolor="#ffffff" align="center">
                            <!-- Header -->
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tbody>
                                <tr>
                                    <td width="50%" align="left"><div style="width:150px;height:60px;padding: 15px 0 0 20px;"><img src="'.zm_get_option('logo').'"  title="'. get_option('blogname').'" style="display:inline;margin:0;max-height:50px;width: auto;" border="0"></div></td>
                                    <td width="50%" align="right"><div style="width:250px;height:60px;line-height:60px;padding-right:20px;">
                                            <a href="'. home_url() .'" title="'. get_option('blogname').'" style="font-size:12px;line-height:60px;color:#222222;text-decoration:none;border:none;padding:0 6px;">首页</a>
                                              
                                        </div></td>
                                </tr>
                                </tbody>
                            </table>
                            <!-- Main Body -->
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tbody>
                                <tr>
                                    <td width="100%">
                                        <div style="padding:20px 20px 40px;font-size:15px;line-height:1.5;color:#3d464d;">
                                            <!-- Content -->
                                            <style>
                        img{max-width:100%;}
                      </style>
                                            <p>'.trim(get_comment($parent_id)->comment_author).', 您好!</p>
                                            <p>您于 '. trim(get_comment($parent_id)->comment_date) . ' 在文章《'.get_the_title($comment->comment_post_ID).'》上发表评论: </p>
                                            <p style="border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;margin:15px 0px;padding-left:20px;padding-right:20px;border-top:#ddd 1px solid;border-right:#ddd 1px solid;padding-top:20px">'. trim(get_comment($parent_id)->comment_content).'</p>
                                            <p>'. trim($comment->comment_author).' 于' . trim($comment->comment_date) . ' 给您的回复如下: </p>
                                            <p style="border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;margin:15px 0px;padding-left:20px;padding-right:20px;border-top:#ddd 1px solid;border-right:#ddd 1px solid;padding-top:20px">'. trim($comment->comment_content).'</p>
                                            <p>您可以点击 <a style="color:#00bbff;text-decoration:none" href="'.htmlspecialchars(get_comment_link($parent_id)).'" target="_blank">查看回复的完整內容</a></p>
                                            <p>感谢你对 <a href="'. home_url() .'" title="'. get_option('blogname').'">' . get_option('blogname') . '</a> 的关注,如您有任何疑问,欢迎在博客留言,我会一一解答</p>
                                            <!-- ./ Content -->
                                        </div>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                            <!-- Footer -->
                        </td>
                    </tr>
                    <tr>
                        <!-- Outer Footer -->
                        <td width="100%" align="center" style="font-size:10px;line-height: 1.5;color: #999999;padding: 5px 0;text-align:center;">
                            <p style="margin:10px 0 0;">此为系统自动发送邮件, 请勿直接回复.</p>
                            <p style="margin:10px 0 0;">版权所有 © '. date("Y") . ' ' . get_option('blogname').'</p>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </td>
        </tr>
        </tbody>
    </table>
</div>';
    $from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
    $headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
    wp_mail( $to, $subject, $message, $headers );
  }
}
if (zm_get_option('mail_notify')) {
add_action('comment_post', 'comment_mail_notify');
}

将上面的代码替换知更鸟的回复邮件模板页inc\email-notify.php,2019年的主题是这个文件,以前的是inc\notify.php这个文件。
其他主题自己找到文件替换,或者去掉开头的<?php if ( ! defined( 'ABSPATH' ) ) { exit; }放到主题的functions.php文件试试。

版权声明:一为 发表于 5年前,共 4746 字。
转载请注明:WordPress邮件回复样式,美化样式 | 一为忆

您可能感兴趣的

2 条评论

  • avatar

    时光菌 ( VIP 1 )

    四川
    回复

    请问WebStack Pro主题zm_get_option('logo')怎么改?如果改成图片地址的话,在哪看这个地址呢,填上去的格式是什么呢?