昨天没事看到官网邮件发送插件,发送的邮件有点太简单,不够美观,于是开始折腾,一直折腾到凌晨2点,终于全部搞定了,上个效果图:
还有另外一个样式自己留着用,有想改的也可以在下面的代码里修改,上代码(是以3.8版本作为基础的,其他版本不保证能用,代码需要适当修改,更名为kl_sendmail.php放在content\plugins\kl_sendmail插件目录,这样原文件的备份)
<?php
/*
Plugin Name: Sendmail
Version: 3.8
Plugin URL: http://kller.cn/?post=61
Description: 发送博客留言至E-mail。
Author: KLLER
Author Email: kller@foxmail.com
Author URL: http://kller.cn
*/
!defined('EMLOG_ROOT') && exit('access deined!');
require_once(EMLOG_ROOT.'/content/plugins/kl_sendmail/class/class.smtp.php');
require_once(EMLOG_ROOT.'/content/plugins/kl_sendmail/class/class.phpmailer.php');
function kl_sendmail_do($mailserver, $port, $mailuser, $mailpass, $mailto, $subject, $content, $fromname)
{
$mail = new KL_SENDMAIL_PHPMailer();
$mail->CharSet = "UTF-8";
$mail->Encoding = "base64";
$mail->Port = $port;
if(KL_MAIL_SENDTYPE == 1)
{
$mail->IsSMTP();
}else{
$mail->IsMail();
}
$mail->Host = $mailserver;
$mail->SMTPAuth = true;
$mail->Username = $mailuser;
$mail->Password = $mailpass;
$mail->From = $mailuser;
$mail->FromName = $fromname;
$mail->AddAddress($mailto);
$mail->WordWrap = 500;
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $content;
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if($mail->Host == 'smtp.gmail.com') $mail->SMTPSecure = "ssl";
if(!$mail->Send())
{
echo $mail->ErrorInfo;
return false;
}else{
return true;
}
}
function kl_sendmail_get_comment_mail()
{
include(EMLOG_ROOT.'/content/plugins/kl_sendmail/kl_sendmail_config.php');
if(KL_IS_SEND_MAIL == 'Y' || KL_IS_REPLY_MAIL == 'Y')
{
$comname = isset($_POST['comname']) ? addslashes(trim($_POST['comname'])) : '';
$comment = isset($_POST['comment']) ? addslashes(trim($_POST['comment'])) : '';
$commail = isset($_POST['commail']) ? addslashes(trim($_POST['commail'])) : '';
$comurl = isset($_POST['comurl']) ? addslashes(trim($_POST['comurl'])) : '';
$gid = isset($_POST['gid']) ? intval($_POST['gid']) : (isset($_GET['gid']) ? intval($_GET['gid']) : -1);
$pid = isset($_POST['pid']) ? intval($_POST['pid']) : 0;
$http_referer = empty($_SERVER['HTTP_REFERER']) ? BLOG_URL : $_SERVER['HTTP_REFERER'];
$blogname = Option::get('blogname');
$Log_Model = new Log_Model();
$logData = $Log_Model->getOneLogForHome($gid);
$log_title = $logData['log_title'];
$subject = "日志《{$log_title}》收到了新的评论";
if(strpos(KL_MAIL_TOEMAIL, '@139.com') === false)
{
$content = "评论内容:{$comment}<br /><br />发件人:".$comname."<br />";
if(!empty($commail)) $content .= "Email:{$commail}<br />";
if(!empty($comurl)) $content .= "主页:{$comurl}<br />";
$content .= "<br /><strong>=> 现在就前往<a href=\"{$http_referer}\" target=\"_blank\">日志页面</a>进行查看</strong><br />";
}else{
$content = $comment;
}
if(KL_IS_SEND_MAIL == 'Y')
{
if(ROLE == 'visitor') kl_sendmail_do(KL_MAIL_SMTP, KL_MAIL_PORT, KL_MAIL_SENDEMAIL, KL_MAIL_PASSWORD, KL_MAIL_TOEMAIL, $subject, $content, $blogname);
}
if(KL_IS_REPLY_MAIL == 'Y')
{
if($pid > 0)
{
$DB = Option::EMLOG_VERSION >= '5.3.0' ? Database::getInstance() : MySql::getInstance();
$Comment_Model = new Comment_Model();
$pinfo = $Comment_Model->getOneComment($pid);
if(!empty($pinfo['mail']))
{
$subject = "您在【骑猪看月亮】发表的评论收到了回复";
$content ='
<div align="center" style="font: 13px/1.5 microsoft yahei,Verdana,Arial,Helvetica,sans-serif;">
<br/><br/>
<div align="left" style="text-decoration:none;width:580px;font-size:14px;padding:10px 15px;margin-bottom:20px;border:1px solid #ccc;border-radius:4px;">
<div align="center"><strong><span style="font-size:28px;color:#08d;">骑猪看月亮</span></strong></div>
<p><strong>'.$pinfo['poster'].'</strong> , 您好:</p>
<p><strong> 您之前在 《'.$log_title.'》 发表的的评论:</strong></p>
<p> '.$pinfo['comment'].'</p>
<p><strong>'.$comname.'</strong> 给您的回复:</p>
<p> '.$comment.'</p>
<p><strong>您可以点击 <a href="'.Url::log($gid).'" style="text-decoration: none;outline:none;" target="_blank">查看该日志</a></strong></p>
<p><strong>感谢您对 <a href="'.BLOG_URL.'" style="text-decoration: none;outline:none;" target="_blank">'.$blogname.'</a> 的关注, 欢迎 <a href="'.BLOG_URL.'rss.php" style="text-decoration: none;outline:none;" target="_blank">订阅本站</a></strong></p>
<p style="color:#999; margin:26px 0 0 0; font-size:12px;">
骑猪看月亮的博客:<a href="https://www.ipve.cn" target="_blank" style="color:#999;">https://www.ipve.cn</a><br>
<span style="text-align:right;background:#ccc;height:1px;widli:100%;overflow:hidden;display:block;margin:8px 0;"></span>
骑猪看月亮<br>
'.gmdate("Y年 m月 d日",time()+8*3600).'
</p>
</div>
<p>Powered by <a href="https://www.ipve.cn" style="text-decoration: none;outline:none;" target="_blank" title="骑猪看月亮">www.ipve.cn</a></p>
<br/>
</div>';
kl_sendmail_do(KL_MAIL_SMTP, KL_MAIL_PORT, KL_MAIL_SENDEMAIL, KL_MAIL_PASSWORD, $pinfo['mail'], $subject, $content, $blogname);
}
}
}
}else{
return;
}
}
addAction('comment_saved', 'kl_sendmail_get_comment_mail');
function kl_sendmail_get_twitter_mail($r, $name, $date, $tid)
{
include(EMLOG_ROOT.'/content/plugins/kl_sendmail/kl_sendmail_config.php');
if(KL_IS_TWITTER_MAIL == 'Y')
{
$DB = Option::EMLOG_VERSION >= '5.3.0' ? Database::getInstance() : MySql::getInstance();
$blogname = Option::get('blogname');
$sql = "select a.content, b.username from ".DB_PREFIX."twitter a left join ".DB_PREFIX."user b on b.uid=a.author where a.id={$tid}";
$res = $DB->query($sql);
$row = $DB->fetch_array($res);
$author = $row['username'];
$twitter = $row['content'];
$subject = "{$author}发布的碎语收到了新的回复";
if(strpos(KL_MAIL_TOEMAIL, '@139.com') === false)
{
$content = "{$author}发布的碎语:{$twitter}<br /><br />{$name}对碎语的回复:{$r}<br /><br /><strong>=> 现在就前往<a href=\"{$_SERVER['HTTP_REFERER']}\" target=\"_blank\">碎语页面</a>进行查看</strong><br />";
}else{
$content = $r;
}
if(ROLE == 'visitor') kl_sendmail_do(KL_MAIL_SMTP, KL_MAIL_PORT, KL_MAIL_SENDEMAIL, KL_MAIL_PASSWORD, KL_MAIL_TOEMAIL, $subject, $content, $blogname);
}
}
addAction('reply_twitter', 'kl_sendmail_get_twitter_mail');
function kl_sendmail_put_reply_mail($commentId, $reply)
{
global $userData;
include(EMLOG_ROOT.'/content/plugins/kl_sendmail/kl_sendmail_config.php');
if(KL_IS_REPLY_MAIL == 'Y')
{
$DB = Option::EMLOG_VERSION >= '5.3.0' ? Database::getInstance() : MySql::getInstance();
$blogname = Option::get('blogname');
$Comment_Model = new Comment_Model();
$commentArray = $Comment_Model->getOneComment($commentId);
extract($commentArray);
$subject="您在【{$blogname}】发表的评论收到了回复";
if(strpos($mail, '@139.com') === false)
{
$emBlog = new Log_Model();
$logData = $emBlog->getOneLogForHome($gid);
$log_title = $logData['log_title'];
$content = '
<div align="center" style="font: 13px/1.5 microsoft yahei,Verdana,Arial,Helvetica,sans-serif;">
<br/><br/>
<div align="left" style="text-decoration:none;width:580px;font-size:14px;padding:10px 15px;margin-bottom:20px;border:1px solid #ccc;border-radius:4px;">
<div align="center"><strong><span style="font-size:28px;color:#08d;">骑猪看月亮</span></strong></div>
<p><strong>'.$poster.'</strong> ,您好:</p>
<p><strong> 您之前在 《'.$log_title.'》 发表的的评论:</strong></p>
<p> '.$comment.'</p>
<p><strong>'.$userData['nickname'].'</strong> 给您的回复:</p>
<p> '.$reply.'</p>
<p><strong>您可以点击 <a href="'.Url::log($gid).'" style="text-decoration: none;outline:none;" target="_blank">查看该日志</a></strong></p>
<p><strong>感谢您对 <a href="'.BLOG_URL.'" style="text-decoration: none;outline:none;" target="_blank">'.$blogname.'</a> 的关注, 欢迎 <a href="'.BLOG_URL.'rss.php" style="text-decoration: none;outline:none;" target="_blank">订阅本站</a></strong></p>
<p style="color:#999; margin:26px 0 0 0; font-size:12px;">
骑猪看月亮的博客:<a href="https://www.ipve.cn" target="_blank" style="color:#999;">https://www.ipve.cn</a><br>
<span style="text-align:right;background:#ccc;height:1px;widli:100%;overflow:hidden;display:block;margin:8px 0;"></span>
骑猪看月亮<br>
'.gmdate("Y年 m月 d日",time()+8*3600).'
</p>
</div>
<p>Powered by <a href="https://www.ipve.cn" style="text-decoration: none;outline:none;" target="_blank" title="骑猪看月亮">www.ipve.cn</a></p>
<br/>
</div>';
}else{
$content = $reply;
}
if($mail != '') kl_sendmail_do(KL_MAIL_SMTP, KL_MAIL_PORT, KL_MAIL_SENDEMAIL, KL_MAIL_PASSWORD, $mail, $subject, $content, $blogname);
}else{
return;
}
}
addAction('comment_reply', 'kl_sendmail_put_reply_mail');
function kl_sendmail_menu()
{
echo '<div class="sidebarsubmenu" id="kl_sendmail"><a href="./plugin.php?plugin=kl_sendmail">sendmail</a></div>';
}
addAction('adm_sidebar_ext', 'kl_sendmail_menu');
?>
