有时我们需要给会员群发邮件,但phpcms v9是没有这个功能的,所以我们自己扩展一下。
下面是实现步骤:
1.找到phpcms v9里面phpcms/modules/member/templates/member_list.tpl.php 在97行后面添加
代码如下:
2.在member_list.tpl.php的页面里添加一段js代码
代码如下:
function emails()
{
var ids='';
$("input[name='userid[]']:checked").each(function(i, n){
ids += $(n).val() + ',';
});
if(ids=='') {
window.top.art.dialog({content:'',lock:true,width:'200',height:'50',time:1.5},function(){});
return false;
}
window.top.art.dialog({id:'emails'}).close();
window.top.art.dialog({title:'发送邮件',id:'emails',iframe:'?m=member& c=member&a=emails&ids='+ids,width:'700',height:'400'}, function(){var d = window.top.art.dialog({id:'emails'}).data.iframe;d.$('#dosubmit').click();return false;}, function(){window.top.art.dialog({id:'emails'}).close()});
}
{
var ids='';
$("input[name='userid[]']:checked").each(function(i, n){
ids += $(n).val() + ',';
});
if(ids=='') {
window.top.art.dialog({content:'',lock:true,width:'200',height:'50',time:1.5},function(){});
return false;
}
window.top.art.dialog({id:'emails'}).close();
window.top.art.dialog({title:'发送邮件',id:'emails',iframe:'?m=member& c=member&a=emails&ids='+ids,width:'700',height:'400'}, function(){var d = window.top.art.dialog({id:'emails'}).data.iframe;d.$('#dosubmit').click();return false;}, function(){window.top.art.dialog({id:'emails'}).close()});
}
3.找到phpcms/modules/member/member.php添加下面代码:
代码如下:
/**
* 群发邮件
*/
function emails()
{
if(isset($_POST['dosubmit'])) {
pc_base::load_sys_func('mail');
$ids = isset($_POST['emails']['ids']) ? explode(',', $_POST['emails']['ids']): showmessage(L('illegal_parameters'), HTTP_REFERER);
array_pop($ids);
if(!empty($ids)) {
$where = to_sqls($ids, '', 'userid');
$userarr = $this->db->listinfo($where);
$emailetitle=$_POST['emails']['title']." - www.freemoban.com";
$emailcontent=$_POST['emails']['content'];
foreach($userarr as $k =>$v)
{
sendmail($v['email'],$emailetitle,$emailcontent);
}
showmessage("邮件发送成功", HTTP_REFERER, '2000', 'emails');
} else {
showmessage(L('illegal_parameters'), HTTP_REFERER, '', 'emails');
}
}else
{
$ids =$_GET['ids'];
include $this->admin_tpl('member_email');
}
}
* 群发邮件
*/
function emails()
{
if(isset($_POST['dosubmit'])) {
pc_base::load_sys_func('mail');
$ids = isset($_POST['emails']['ids']) ? explode(',', $_POST['emails']['ids']): showmessage(L('illegal_parameters'), HTTP_REFERER);
array_pop($ids);
if(!empty($ids)) {
$where = to_sqls($ids, '', 'userid');
$userarr = $this->db->listinfo($where);
$emailetitle=$_POST['emails']['title']." - www.freemoban.com";
$emailcontent=$_POST['emails']['content'];
foreach($userarr as $k =>$v)
{
sendmail($v['email'],$emailetitle,$emailcontent);
}
showmessage("邮件发送成功", HTTP_REFERER, '2000', 'emails');
} else {
showmessage(L('illegal_parameters'), HTTP_REFERER, '', 'emails');
}
}else
{
$ids =$_GET['ids'];
include $this->admin_tpl('member_email');
}
}
4.添加邮件群发调用模板,在phpcms/modules/member//templates下新建一个member_email.tpl.php
里面代码如下:
admin_tpl('header', 'admin');?>
<script type="text/javascript">
$(document).ready(function(){
$.formValidator.initConfig({formid:"myform",autotip:true,onerror:function(msg,obj){window.top.art.dialog({content:msg,lock:true,width:'220',height:'70'}, function(){this.close();$(obj).focus();})}});
$('#title').formValidator({onshow:"",onfocus:"",oncorrect:""}).inputValidator({min:1,onerror:""}).ajaxValidator({type:"get",url:"",
data:"m=announce&c=admin_announce&a=public_check_title",datatype:"html",
cached:false,async:'true',success : function(data)
{
if( data == "1" )
{
return true;
}
else
{
return false;
}
},
error: function(){alert("");},
onerror : "",
onwait : ""
});
$("#content").formValidator({autotip:true,onshow:"",onfocus:""}).functionValidator({
fun:function(val,elem){
//获取编辑器中的内容
var oEditor = CKEDITOR.instances.content;
var data = oEditor.getData();
if(data==''){
return ""
} else {
return true;
}
}
});
});
</script>
然后提交,注意邮件的配置,
成功收到邮件
3个修改文件见附件
http://www.freemoban.com/uploadfile/2016/0921/20160921121609746.rar
if( data == "1" )
{
return true;
}
else
{
return false;
}
},
error: function(){alert("");},
onerror : "",
onwait : ""
});
$("#content").formValidator({autotip:true,onshow:"",onfocus:""}).functionValidator({
fun:function(val,elem){
//获取编辑器中的内容
var oEditor = CKEDITOR.instances.content;
var data = oEditor.getData();
if(data==''){
return ""
} else {
return true;
}
}
});
});
</script>
然后提交,注意邮件的配置,
成功收到邮件
3个修改文件见附件
http://www.freemoban.com/uploadfile/2016/0921/20160921121609746.rar