技术干货

自用评论邮件通知美化模板

果壳 · 8月24日 · 2019年 · ·

效果图

代码

找到function.php,找到里面的评论邮件回复,把样式改成以下代码

<div style="background: white;
      width: 95%;
      max-width: 800px;
      margin: auto auto;
      border-radius: 5px;
      border:orange 1px solid;
      overflow: hidden;
      -webkit-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.12);
      box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.18);">
        <header style="overflow: hidden;">
            <img style="width:100%;z-index: 666;" src="https://cdn.jsdelivr.net/gh/moezx/cdn@3.1.4/img/other/head.jpg">
        </header>
        <div style="padding: 5px 20px;">
        <p style="position: relative;
        color: white;
        float: left;
        z-index: 999;
        background: #91a5a5;
        padding: 5px 30px;
        margin: -25px auto 0 ;
        box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.30)">Dear ' . trim(get_comment($parent_id)->comment_author) . '</p>
        <br>
        <h3><span style="color: #12ADDB;font-weight: bold;">> </span>您有一条来自<a style="text-decoration: none;color: #12ADDB; " target="_blank" href="' .home_url(). '/">'. get_option("blogname") .'</a>的回复</h3>
        <br>
        <p style="font-size: 14px;">您在文章<a style="text-decoration:none;color: #12ADDB;" target="_blank" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">《' . get_the_title($comment->comment_post_ID) . '》</a>上发表的评论:</p>
        <p style="border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;border-radius:6px;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 style="font-size: 14px;">' . trim($comment->comment_author) . ' 给您的回复如下:</p>
        <p style="border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;border-radius:6px;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>
      <div style="text-align: center;">
          <a style="text-transform: uppercase;
                      text-decoration: none;
                      font-size: 14px;
                      border: 2px solid #6c7575;
                      color: #2f3333;
                      border-radius:6px;
                      padding: 10px;
                      display: inline-block;
                      margin: 10px auto 0; " target="_blank" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">点击查看回复的完整內容</a>
      </div>
        <p style="font-size: 12px;text-align: center;color: #999;">本邮件为系统自动发出,请勿直接回复<br>
        © '.date(Y).' '.get_option("blogname").'</p>
      </div>       
    </div>

整个评论邮件回复代码(下面是H-Siren主题的整个替换)

/*
 * 评论邮件回复
 */
function comment_mail_notify($comment_id){
    $mail_user_name = akina_option('mail_user_name') ? akina_option('mail_user_name') : 'poi';
    $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 = $mail_user_name . '@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
    $to = trim(get_comment($parent_id)->comment_author_email);
    $subject = '你在 [' . get_option("blogname") . '] 的留言有了回应';
    $message = '
      <div style="background: white;
      width: 95%;
      max-width: 800px;
      margin: auto auto;
      border-radius: 5px;
      border:orange 1px solid;
      overflow: hidden;
      -webkit-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.12);
      box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.18);">
        <header style="overflow: hidden;">
            <img style="width:100%;z-index: 666;" src="https://cdn.jsdelivr.net/gh/moezx/cdn@3.1.4/img/other/head.jpg">
        </header>
        <div style="padding: 5px 20px;">
        <p style="position: relative;
        color: white;
        float: left;
        z-index: 999;
        background: #91a5a5;
        padding: 5px 30px;
        margin: -25px auto 0 ;
        box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.30)">Dear ' . trim(get_comment($parent_id)->comment_author) . '</p>
        <br>
        <h3><span style="color: #12ADDB;font-weight: bold;">> </span>您有一条来自<a style="text-decoration: none;color: #12ADDB; " target="_blank" href="' .home_url(). '/">'. get_option("blogname") .'</a>的回复</h3>
        <br>
        <p style="font-size: 14px;">您在文章<a style="text-decoration:none;color: #12ADDB;" target="_blank" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">《' . get_the_title($comment->comment_post_ID) . '》</a>上发表的评论:</p>
        <p style="border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;border-radius:6px;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 style="font-size: 14px;">' . trim($comment->comment_author) . ' 给您的回复如下:</p>
        <p style="border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;border-radius:6px;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>
      <div style="text-align: center;">
          <a style="text-transform: uppercase;
                      text-decoration: none;
                      font-size: 14px;
                      border: 2px solid #6c7575;
                      color: #2f3333;
                      border-radius:6px;
                      padding: 10px;
                      display: inline-block;
                      margin: 10px auto 0; " target="_blank" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">点击查看回复的完整內容</a>
      </div>
        <p style="font-size: 12px;text-align: center;color: #999;">本邮件为系统自动发出,请勿直接回复<br>
        © '.date(Y).' '.get_option("blogname").'</p>
      </div>       
    </div>
';
    $message = convert_smilies($message);
    $message = str_replace("{{",'<img src="https://cdn.jsdelivr.net/gh/moezx/cdn@2.9.4/img/bili/hd/ic_emoji_',$message);
    $message = str_replace("}}",'.png" alt="emoji" style="height: 2em; max-height: 2em;">',$message);

    $message =  str_replace('{UPLOAD}', 'https://i.loli.net/', $message); 
    $message =  str_replace('[/img][img]', '[/img^img]', $message);  

    $message =  str_replace('[img]', '<img src="', $message); 
    $message =  str_replace('[/img]', '" style="width:80%;display: block;margin-left: auto;margin-right: auto;">', $message); 

    $message =  str_replace('[/img^img]', '" style="width:80%;display: block;margin-left: auto;margin-right: auto;"><img src="', $message);
    $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 );
  }
}
add_action('comment_post', 'comment_mail_notify');

感谢师所长的分享!

0 条回应


页面加载用时0.118 s
在线人数:1人