登陆
最新消息: 老是忘了更新啊~~


修改Emlog插件sendmail的邮件发送样式

技巧资料 骑猪看月亮 6318次浏览 18条评 论

      昨天没事看到官网邮件发送插件,发送的邮件有点太简单,不够美观,于是开始折腾,一直折腾到凌晨2点,终于全部搞定了,上个效果图:

修改Emlog插件sendmail的发送样式

      还有另外一个样式自己留着用,有想改的也可以在下面的代码里修改,上代码(是以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>&nbsp;&nbsp;&nbsp;&nbsp;您之前在 《'.$log_title.'》 发表的的评论:</strong></p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;'.$pinfo['comment'].'</p>
               <p><strong>'.$comname.'</strong> 给您的回复:</p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;'.$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="http://www.qzkyl.cn" target="_blank" style="color:#999;">http://www.qzkyl.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="http://www.qzkyl.cn" style="text-decoration: none;outline:none;" target="_blank" title="骑猪看月亮">www.qzkyl.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>&nbsp;&nbsp;&nbsp;&nbsp;您之前在 《'.$log_title.'》 发表的的评论:</strong></p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;'.$comment.'</p>
               <p><strong>'.$userData['nickname'].'</strong> 给您的回复:</p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;'.$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="http://www.qzkyl.cn" target="_blank" style="color:#999;">http://www.qzkyl.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="http://www.qzkyl.cn" style="text-decoration: none;outline:none;" target="_blank" title="骑猪看月亮">www.qzkyl.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');
?>


囧 亲 晕 酷 哭 馋 闭嘴 调皮 贪 奸 怒 嘿 羞 汗 色 惊 萌 悲 笑 惊 狂 吃
囧 亲 晕 酷 哭 馋 闭嘴 调皮 贪 奸 怒 嘿 羞 汗 色 惊 萌 悲 笑 惊 狂 吃

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论(18)

  1. avatar
    怎么不直接弄出来个emlog插件呢
    明浩 2016-01-18 16:43 回复
  2. avatar
    感谢楼主給的灵感
    alen 2015-08-31 11:03 回复
    • avatar
      @alen:好东西就是分享的
      骑猪看月亮 2015-08-31 11:26 回复
      • avatar
        @骑猪看月亮:有好看的样式嘛?我参照威锋的改了个。
        alen 2015-08-31 13:26 回复
        • avatar
          @alen:没有其他样式了,就这个你可以自己对照好看的改
          骑猪看月亮 2015-09-01 23:46 回复
  3. avatar
    博主能给个emlog论坛的邀请吗?谢谢我打算从PJblog换emlog,
    5ijoy 2015-05-09 14:37 回复
    • avatar
      @5ijoy:最近上班太忙一直没顾上回复,我论坛级别还不是很高,没得邀请码啊
      骑猪看月亮 2015-05-13 15:47 回复
  4. avatar
    http://7xinvl.com1.z0.glb.clouddn.com/U~DPX3O_H]}`G)CRWZ%25%25BFE.png 可能我没表达明白,就是我收到别人的评论  邮件样式是这样的,怎么改啊
    过路人博客 2015-05-07 21:03 回复
  5. avatar
    是我放置文件的问题吗?为什么我照你说的放进去还是原来的样式?插件版本是3.8的   看到请务必回复下  谢谢
    过路人博客 2015-05-06 21:54 回复
    • avatar
      @过路人博客:我的也是3.8的,你就按上面的改应该不会出问题的,你看下改的地方对吗?
      骑猪看月亮 2015-05-07 19:45 回复
      • avatar
        @骑猪看月亮:可以留个QQ吗?在线请教一下,有点小小的问题不知道怎么解决QQ  764018154
        过路人博客 2015-05-07 19:48 回复
        • avatar
          @过路人博客:我刚才看了下,文件名应该是kl_sendmail.php,文件放在content\plugins\kl_sendmail目录下
          骑猪看月亮 2015-05-07 19:50 回复
          • avatar
            @骑猪看月亮:那个搞出来了,主要是样式问题,别人收到邮件是您的样式,我收到别人的评论,样式却是自带的。。。
            过路人博客 2015-05-07 19:51 回复
  6. avatar
    不错不错,貌似官网现在有两款sendmail插件,不过还是喜欢这款
    迷糊小侠 2015-02-11 12:15 回复
    • avatar
      @迷糊小侠:最近工作有点忙,企业邮箱出了点问题,结果邮件不能自动发了,你现在可以看看是啥样
      骑猪看月亮 2015-02-11 17:47 回复