php发送邮件功能整合到thinkphp

互联网的时代,email必不可少。有时候有留言功能的话,后台再配合一个邮件发送功能,也就是当回复留言的时候可以用邮件通知留言者。这样想必可以增加不少网站的友好度和回头率。

现在我将这个功能整合了一下。发个核心的代码,仅供参考。

先将一个smtp类和发送邮件类(SendMail.class.php)放到 wwwrootThinkphpExtendLibraryORGUtil 目录下。

SendMail.class.php:

<?php

class SendMail{

//****************************************************

var $smtpserver = "smtp.126.com";//SMTP服务器

var $smtpserverport =25;//SMTP服务器端口

var $smtpusermail = "daixiaorui@126.com";//SMTP服务器的用户邮箱(邮箱名是举的例子)

var $smtpuser = "daixiaorui";//SMTP服务器的用户帐号

var $smtppass = "123456";//SMTP服务器的用户密码

var $mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件

//****************************************************

public function __construct($mailto,$username,$mailcontent){

$mailtitle = "亲爱的"".$username."",您的留言/评论有了新回复";

//这里面的一个true是表示使用身份验证,否则不使用身份验证.

$smtp = new Smtp($this->smtpserver,$this->smtpserverport,true,$this->smtpuser,$this->smtppass);

//是否显示发送的调试信息

$smtp->debug = false;

$state = $smtp->sendmail($mailto,$this->smtpusermail,$mailtitle,$mailcontent,$this->mailtype);

}

}

?>

然后 后台回复留言的时候调用就行了:

public function reply(){

$com = D("Guestbooks");

$thiscid = I("asid");

$mailto = I("mailto");

$thiscom = $com->where("id=$mailto")->find();

if($com->create()){

//送用户发送邮件

//引入类

import("ORG.Util.Smtp");

import("ORG.Util.SendMail");

$content = '<p>亲爱的<b>"'.$thiscom['username'].'"</b>,您好:</p><p>&nbsp;</p><p>您在&nbsp;<a href="http://www.daixiaorui.com/" target="_blank">代潇瑞博客-专注于PHP学习,互联网分享</a>&nbsp;的留言有了新回复,请点击下面链接查看详细的回复内容,谢谢您的光临!!</p><p><a href="http://www.daixiaorui.com/Guestbook/#floor'.$thiscid.'" target="_blank">http://www.daixiaorui.com/Guestbook/#floor'.$thiscid.'</a></p><p>&nbsp;</p><p><font color="red">如果不是您的回复,可以不用进行理睬。</font><p><p>&nbsp;</p><p>本邮件来自:<a href="http://www.daixiaorui.com/" target="_blank">代潇瑞博客-专注于PHP学习,互联网分享</a>&nbsp。欢迎前来阅读。<p>';

//echo $content; exit();

new SendMail($thiscom['email'],$thiscom['username'],$content);

$this->okOrFailed($com->add(),/Dmanage.php/Article."/index");

}else{

$this->error($com->getError(),"");

}

}

相关文章

(1)创建数据表: CREATE TABLE IF NOT EXISTS `think_form` ...
组合查询的主体还是采用数组方式查询,只是加入了一些特殊的...
(1)创建模版:/App/Home/View/Form/edit.html   <FORM m...
自定义配置文件user.php: <?php return array(    \'se...
在一些成熟的CMS系统中,后台一般都包含一个配置中心(如织梦...
废话不多说先上图预览下,即本博客的分页; 这个分页类是在...