最新消息:本站原qzkyl域名已转让,后期该域名所有言论与本站无关,同时本站已改名ipve虚拟机,交换友链请发送邮件zc#ipve.cn(#换@)

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

WordPress ipve 355浏览 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="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>&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="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');
?>

发表我的评论
取消评论
表情

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

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

网友最新评论 (18)

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