WordPress评论邮件通知代码
有的主题自带这个功能,但是不够美观,用疯子的世界告诉我的这个代码,就美观多了!

//评论邮件通知 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 = 'admin@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));//发件人e-mail地址 $to = trim(get_comment($parent_id)->comment_author_email); $subject = '你在 [' . get_the_title($comment->comment_post_ID) . '] 的评论有回复啦 by:' . get_option('blogname') . ''; $message = ' <div id="isForwardContent"><div style="color:#555;font:12px/1.5 微软雅黑,Tahoma,Helvetica,Arial,sans-serif;width:600px;margin:50px auto;border: 1px solid #e9e9e9;border-top: none;box-shadow:0 0px 0px #aaaaaa;"> <table border="0" cellspacing="0" cellpadding="0"> <tbody> <tr valign="top" height="2"> <td width="190" bgcolor="#0B9938"></td> <td width="120" bgcolor="#9FCE67"></td> <td width="85" bgcolor="#EDB113"></td> <td width="85" bgcolor="#FFCC02"></td> <td width="130" bgcolor="#5B1301" valign="top"></td> </tr> </tbody> </table> <div style="padding: 0 15px 8px;"> <h2 style="border-bottom:1px solid #e9e9e9;font-size:14px;font-weight:normal;padding:10px 0 10px;"><span style="color: #12ADDB">> </span>您在 <a style="text-decoration:none;color: #12ADDB;" href="http://www.zntec.cn" title="' . get_option('blogname') . '" target="_blank">' . get_option('blogname') . '</a> 中的留言有回复啦!</h2> <div style="font-size:12px;color:#777;padding:0 10px;margin-top:18px">' . trim(get_comment($parent_id)->comment_author) . ' 同学,您曾在《 ' . get_the_title($comment->comment_post_ID) . ' 》中发表评论: <p style="background-color: #f5f5f5;padding: 10px 15px;margin:18px 0">' . nl2br(get_comment($parent_id)->comment_content) . '</p> <p>' . trim($comment->comment_author) . ' 给您的回复如下:</p> <p style="background-color:#f5f5f5;padding: 10px 15px;margin:18px 0">' . nl2br($comment->comment_content) . '</p> <p>您可以点击 <a style="text-decoration:none; color:#12addb" href="' . htmlspecialchars(get_comment_link($parent_id)) . '" title="单击查看完整的回复内容" target="_blank">查看完整的回复內容</a>,欢迎再次光临 <a style="text-decoration:none; color:#12addb" href="' . get_option('home') . '" title="' . get_option('blogname') . '" target="_blank">' . get_option('blogname') . '</a>!</p> </div> </div> <div style="color:#888;padding:10px;border-top:1px solid #e9e9e9;background:#f5f5f5;"> <p style="margin:0;padding:0;">2012-2013 <a style="color:#888;text-decoration:none;" href="' . get_option('home') . '" title="' . get_option('blogname') . '" target="_blank">' . get_option('blogname') . '</a> - 邮件自动生成,请勿直接回复!</p> </div> </div> </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 ); //echo 'mail to ', $to, '<br/> ' , $subject, $message; // for testing } } add_action('comment_post', 'comment_mail_notify');
保存下大前端的邮件回复代码
- //评论回应邮件通知
- function comment_mail_notify($comment_id) {
- $admin_notify = '1'; // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 )
- $admin_email = get_bloginfo ('admin_email'); // $admin_email 可改为你指定的 e-mail.
- $comment = get_comment($comment_id);
- $comment_author_email = trim($comment->comment_author_email);
- $parent_id = $comment->comment_parent ? $comment->comment_parent : '';
- global $wpdb;
- if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '')
- $wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
- if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1'))
- $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'");
- $notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0';
- $spam_confirmed = $comment->comment_approved;
- if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') {
- $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 = 'Hi,您在 [' . get_option("blogname") . '] 的留言有人回复啦!';
- $message = '
- <div style="color:#333;font:100 14px/24px microsoft yahei;">
- <p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p>
- <p>您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:<br /> '
- . trim(get_comment($parent_id)->comment_content) . '</p>
- <p>' . trim($comment->comment_author) . ' 给您的回应:<br /> '
- . trim($comment->comment_content) . '<br /></p>
- <p>点击 <a href="' . htmlspecialchars(get_comment_link($parent_id)) . '">查看回应完整內容</a></p>
- <p>欢迎再次光临 <a href="' . get_option('home') . '">' . get_option('blogname') . '</a></p>
- <p style="color:#999">(此邮件由系统自动发出,请勿回复.)</p>
- </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 );
- //echo 'mail to ', $to, '<br/> ' , $subject, $message; // for testing
- }
- }
WordPress评论邮件通知代码:等您坐沙发呢!