2011.01.11(W2)
今天加入了回響(回應)自動發MAIL通知給留言人的功能
必須要修改 wp-content/themes/您所用的模板/functions.php
我的話我是放在 <?php ….. ?> 區域內的最下面.
程式碼如下:
/* comment_mail_notify v1.0 by willin kan. (所有回覆都發郵件) */
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 = ‘
<div style="background-color:#eef2fa; border:1px solid #d8e3e8; color:#111; padding:0 15px; -moz-border-radius:5px; -webkit-border-radius:5px; -khtml-border-radius:5px; border-radius:5px;">
<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>(此郵件由系統自動發出, 請勿回覆.)</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
}
}
add_action(‘comment_post’, ‘comment_mail_notify’);
// — END —————————————-
將程式碼貼上之後就可以完成
發表迴響
抱歉,你必須要登入才能發表迴響喔!