在某些互动性很强的WordPress博客内,开启嵌套评论是一种非常常见的方法,可是大部分访客在发表评论后,很难知道有人曾回复过他的评论,而今天畅想资源就来教大家如何纯代码在WordPress内添加评论回复邮件提醒通知功能,让访客更加方便快捷的了解自己的评论近况!
预览
教学
注意:使用该功能有可能(未经证实!)会由于类似群发而被服务商标识为垃圾邮件,一切后果自负!
提示:如果你需要在新文章发布时邮件通知留言者,请见「【纯代码】WordPress向留言者发送新文章邮件通知教学」!
将下方代码添加到「布景函式库 (functions.php)」的最底部 ?> 之前,然后点击  即可~  
 
提示:你可以将下方代码各高亮部分修改为你想要的配置!
注意:如果您的伺服器并不支持 mail 函数,请参考「这篇文章」并使用外部SMTP发送邮件即可!
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | /* 评论回复邮件提醒通知功能开始(由AREFLY.COM制作) */ function comments_mail_notify($comment_id) { 	$admin_email = get_option('admin_email');			//发件人=站长邮箱 	//$admin_email = "info@domain.com";				//去除本行注释可修改发件人邮箱! 	$comment = get_comment($comment_id); 	$comment_author_email = trim($comment->comment_author_email); 	$parent_id = $comment->comment_parent ? $comment->comment_parent : ''; 	$to = $parent_id ? trim(get_comment($parent_id)->comment_author_email) : ''; 	$spam_confirmed = $comment->comment_approved; 	if (($parent_id != '') && ($spam_confirmed != 'spam') && ($to != $admin_email)) { 		$wp_email = $admin_email; 		$to = trim(get_comment($parent_id)->comment_author_email); 		$subject = '您在「' . get_option("blogname") . '」的留言有了新回复'; 		$message = ' <style> blockquote{ 	padding: 5px 10px; 	margin: 0 5px; 	border: 1px solid #ddd; 	/** border-left: 8px solid #ddd; **/ 	background-color: #e9e9e9; 	overflow: auto; 	border-left-width: 4px; 	font-family: inherit; } blockquote.code, pre{ 	font-family: "Courier New", sans-serif; 	padding: 5px 5px; 	margin: 0; } code{ 	padding: 2px 4px; 	color: #8A2908; 	background: rgba(0, 0, 0, 0.05); 	border: 1px solid rgba(0, 0, 0, 0.1); 	-webkit-border-radius: 3px; 	-moz-border-radius: 3px; 	border-radius: 3px; 	font-size: 12px; 	font-family: "Courier New", sans-serif; 	word-wrap: break-word; 	word-break: break-all; } kbd{ 	padding: 0.1em 0.6em; 	border: 1px solid #cccccc; 	font-size: 11px; 	font-family: Arial, Helvetica, sans-serif; 	background-color: #f7f7f7; 	color: #333333; 	-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0 1px 0, white 0 0 0 2px inset; 	-moz-box-shadow: rgba(0, 0, 0, 0.2) 0 1px 0, white 0 0 0 2px inset; 	box-shadow: rgba(0, 0, 0, 0.2) 0 1px 0, white 0 0 0 2px inset; 	-webkit-border-radius: 3px; 	-moz-border-radius: 3px; 	-ms-border-radius: 3px; 	-o-border-radius: 3px; 	border-radius: 3px; 	text-shadow: white 0 1px 0; 	display: inline-block; 	margin: 0 0.1em; 	line-height: 1.4; 	text-indent: 0em; } p img:not(.wp-smiley){ 	-webkit-border-radius: 6px; 	-moz-border-radius: 6px; 	border-radius: 6px; 	max-width: 400px; 	width: expression(this.width > 400 ? "400px" : true); 	height: auto; } a{ 	color: #12addb; } </style> <div style="color: #555; font-size: 12px; font-family: \'Segoe UI\', \'Segoe\', \'Segoe WP\', \'Tahoma\', \'Microsoft YaHei\', sans-serif; -webkit-font-smoothing: antialiased; width: 600px; margin:0 auto; border: 1px solid #e9e9e9; border-top: none;"> 	<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="' . get_option("home") . '" title="' . get_option("blogname") . '" target="_blank">' . get_option("blogname") . '</a>」中的留言有新回复啦!</h2> 		<div style="font-size:12px;color:#777;padding:0 10px;margin-top:18px"> 			<div class="im"> 				<p>' .trim(get_comment($parent_id)->comment_author) . ' 您好!</p> 				<p>您曾在本站文章「' . get_the_title($comment->comment_post_ID) . '」中发表留言:</p> 				<p style="background-color:#f5f5f5;padding:10px 15px;margin:18px 0"> ' .nl2br(get_comment($parent_id)->comment_content) . ' </p> 			</div> 			<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)) . '" target="_blank">查看回复的完整内容</a>」</p> 			<p>欢迎再次光临「<a style="text-decoration:none; color:#12addb" href="' . get_option('home') . '" 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"><span style="color:#BDBDBD">© <a style="color: #888; text-decoration: none;" href="' . get_option("home") . '" title="' . get_option("blogname") . '" target="_blank">' . get_option("blogname") . '</a> 请添加 <a style="color:#BDBDBD" href="mailto:'.get_option('admin_email').'">'.get_option('admin_email').'</a> 至您的通讯录,以便接收本站邮件,谢谢!</span></p> 	</div> </div> 		'; 		$message = do_shortcode(convert_smilies($message)); 		$from = "From: \"" . htmlspecialchars(get_option('blogname'),ENT_QUOTES) . "\" <$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;		//仅供测试! 	} } add_action('comment_post', 'comments_mail_notify'); /* 评论回复邮件提醒通知功能结束(由AREFLY.COM制作) */ | 
 
		