方维o2o生活服务系统V2.9不会自动发送邮件及短信的解决办法

  • PHP二次开发网
  • 2013-11-26 12:51
  • PHP二次开发网
  • 阅读(3150)
  • 评论(0)
  • 摘要: 方维o2o生活服务系统在升级到V2.6之后,好像都无法自动发送邮件及短信,需要在后台列表里面触发才行,这样很不方便,解决方法如下。 找到文件:admin/lib/action/DealMsgListAction.class.php ... ...
    方维o2o生活服务系统在升级到V2.6之后,好像都无法自动发送邮件及短信,需要在后台列表里面触发才行,这样很不方便,解决方法如下。

    找到文件:admin/lib/action/DealMsgListAction.class.php

    在文件中加入这样一个函数:

    [代码]php代码:

    public function sendid($id)
    	{
    		$id = isset($id)? intval($id) : $_REQUEST ['id'];
    		$msg_item = M('DealMsgList')->getById($id);
    		if($msg_item)
    		{
    			if($msg_item['send_type']==0)
    			{
    				require_once APP_ROOT_PATH.'system/utils/es_sms.php';
    				$sms = new sms_sender();
    				$result = $sms->sendSms($msg_item['dest'],$msg_item['content']);
    				$msg_item['result'] = $result['msg'];
    				$msg_item['is_success'] = intval($result['status']);
    				$msg_item['send_time'] = get_gmtime();
    				M('DealMsgList')->save($msg_item);
    				if($result['status'])
    				{
    					header('Content-Type:text/html; charset=utf-8');
    					//echo l('SEND_NOW').l('SUCCESS');
    				}
    				else
    				{
    					header('Content-Type:text/html; charset=utf-8');
    					//echo l('SEND_NOW').l('FAILED').$result['msg'];
    				}
    			}
    			else
    			{
    				require_once APP_ROOT_PATH.'system/utils/es_mail.php';
    				$mail = new mail_sender();
    				$mail->AddAddress($msg_item['dest']);
    				$mail->IsHTML($msg_item['is_html']);
    				$mail->Subject = $msg_item['title'];
    				$mail->Body = $msg_item['content'];
    				$result = $mail->Send();
    				$msg_item['result'] = $mail->ErrorInfo;
    				$msg_item['is_success'] = intval($result);
    				$msg_item['send_time'] = get_gmtime();
    				M('DealMsgList')->save($msg_item);
    				if($result)
    				{
    					header('Content-Type:text/html; charset=utf-8');
    					//echo l('SEND_NOW').l('SUCCESS');
    				}
    				else
    				{
    					header('Content-Type:text/html; charset=utf-8');
    					//echo l('SEND_NOW').l('FAILED').$mail->ErrorInfo;
    				}
    			}
    		}
    		else
    		{
    			header('Content-Type:text/html; charset=utf-8');
    			//echo l('SEND_NOW').l('FAILED');
    		}
    	}

    然后找到文件:system/common.php

    找到发送邮件的函数:

    [代码]php代码:

    //发邮件团购券
    function send_deal_coupon_mail($deal_coupon_id)
    {
    	if(app_conf("MAIL_ON")==1&&app_conf("MAIL_SEND_COUPON")==1)
    	{
    		$coupon_data = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."deal_coupon where id = ".$deal_coupon_id);			
    		if($coupon_data)
    		{
    			$tmpl = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."msg_template where name = 'TPL_MAIL_COUPON'");
    			$tmpl_content = $tmpl['content'];
    			$coupon_data['begin_time_format'] = $coupon_data['begin_time']==0?$GLOBALS['lang']['NO_BEGIN_TIME']:to_date($coupon_data['begin_time'],'Y-m-d');
    			$coupon_data['end_time_format'] = $coupon_data['end_time']==0?$GLOBALS['lang']['NO_END_TIME']:to_date($coupon_data['end_time'],'Y-m-d');			
    			$user_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$coupon_data['user_id']);
    			$coupon_data['user_name'] = $user_info['user_name'];
    			$coupon_data['deal_name'] = $GLOBALS['db']->getOne("select name from ".DB_PREFIX."deal_order_item where id = ".$coupon_data['order_deal_id']);
    			$coupon_data['deal_sub_name'] = $GLOBALS['db']->getOne("select sub_name from ".DB_PREFIX."deal_order_item where id = ".$coupon_data['order_deal_id']);
    					$deal_id = $coupon_data['deal_id'];
    					if(!$coupon_data['deal_name']||!$coupon_data['deal_sub_name'])
    					{
    						$deal_info = $GLOBALS['db']->getRow("select name,sub_name from ".DB_PREFIX."deal where id = ".$deal_id);
    						if(!$coupon_data['deal_name'])
    						$coupon_data['deal_name'] = $deal_info['name'];
    						if(!$coupon_data['deal_sub_name'])
    						$coupon_data['deal_sub_name'] = $deal_info['sub_name'];
    					}	
    			$order_item = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."deal_order_item where id = ".intval($coupon_data['order_deal_id']));
    			$deal_type = intval($GLOBALS['db']->getOne("select deal_type from ".DB_PREFIX."deal where id = ".intval($order_item['deal_id'])));
    			if($deal_type == 1&&$order_item)
    			{
    					$coupon_data['deal_name'].= " ".$GLOBALS['lang']['BUY_NUMBER']."(".$order_item['number'].")";
    					$coupon_data['deal_sub_name'].= " ".$GLOBALS['lang']['BUY_NUMBER']."(".$order_item['number'].")";
    			}
    			
    			$GLOBALS['tmpl']->assign("coupon",$coupon_data);
    			$msg = $GLOBALS['tmpl']->fetch("str:".$tmpl_content);
    			$msg_data['dest'] = $user_info['email'];
    			$msg_data['send_type'] = 1;
    			$msg_data['title'] = $GLOBALS['lang']['YOU_GOT_COUPON'];
    			$msg_data['content'] = addslashes($msg);
    			$msg_data['send_time'] = 0;
    			$msg_data['is_send'] = 0;
    			$msg_data['create_time'] = get_gmtime();
    			$msg_data['user_id'] = $user_info['id'];
    			$msg_data['is_html'] = $tmpl['is_html'];
    			$GLOBALS['db']->autoExecute(DB_PREFIX."deal_msg_list",$msg_data); //插入
    		}
    	}
    }

    将其修改为:

    [代码]php代码:

    //发邮件团购券
    function send_deal_coupon_mail($deal_coupon_id)
    {
    	if(app_conf("MAIL_ON")==1&&app_conf("MAIL_SEND_COUPON")==1)
    	{
    		$coupon_data = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."deal_coupon where id = ".$deal_coupon_id);			
    		if($coupon_data)
    		{
    			$tmpl = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."msg_template where name = 'TPL_MAIL_COUPON'");
    			$tmpl_content = $tmpl['content'];
    			$coupon_data['begin_time_format'] = $coupon_data['begin_time']==0?$GLOBALS['lang']['NO_BEGIN_TIME']:to_date($coupon_data['begin_time'],'Y-m-d');
    			$coupon_data['end_time_format'] = $coupon_data['end_time']==0?$GLOBALS['lang']['NO_END_TIME']:to_date($coupon_data['end_time'],'Y-m-d');			
    			$user_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$coupon_data['user_id']);
    			$coupon_data['user_name'] = $user_info['user_name'];
    			$coupon_data['deal_name'] = $GLOBALS['db']->getOne("select name from ".DB_PREFIX."deal_order_item where id = ".$coupon_data['order_deal_id']);
    			$coupon_data['deal_sub_name'] = $GLOBALS['db']->getOne("select sub_name from ".DB_PREFIX."deal_order_item where id = ".$coupon_data['order_deal_id']);
    					$deal_id = $coupon_data['deal_id'];
    					if(!$coupon_data['deal_name']||!$coupon_data['deal_sub_name'])
    					{
    						$deal_info = $GLOBALS['db']->getRow("select name,sub_name from ".DB_PREFIX."deal where id = ".$deal_id);
    						if(!$coupon_data['deal_name'])
    						$coupon_data['deal_name'] = $deal_info['name'];
    						if(!$coupon_data['deal_sub_name'])
    						$coupon_data['deal_sub_name'] = $deal_info['sub_name'];
    					}	
    			$order_item = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."deal_order_item where id = ".intval($coupon_data['order_deal_id']));
    			$deal_type = intval($GLOBALS['db']->getOne("select deal_type from ".DB_PREFIX."deal where id = ".intval($order_item['deal_id'])));
    			if($deal_type == 1&&$order_item)
    			{
    					$coupon_data['deal_name'].= " ".$GLOBALS['lang']['BUY_NUMBER']."(".$order_item['number'].")";
    					$coupon_data['deal_sub_name'].= " ".$GLOBALS['lang']['BUY_NUMBER']."(".$order_item['number'].")";
    			}
    			
    			$GLOBALS['tmpl']->assign("coupon",$coupon_data);
    			$msg = $GLOBALS['tmpl']->fetch("str:".$tmpl_content);
    			$msg_data['dest'] = $user_info['email'];
    			$msg_data['send_type'] = 1;
    			$msg_data['title'] = $GLOBALS['lang']['YOU_GOT_COUPON'];
    			$msg_data['content'] = addslashes($msg);
    			$msg_data['send_time'] = 0;
    			$msg_data['is_send'] = 0;
    			$msg_data['create_time'] = get_gmtime();
    			$msg_data['user_id'] = $user_info['id'];
    			$msg_data['is_html'] = $tmpl['is_html'];
    			$GLOBALS['db']->autoExecute(DB_PREFIX."deal_msg_list",$msg_data); //插入
    			
    			//获取刚刚插入的数据ID,并实现邮件的发送
    			$send_mail_id = mysql_insert_id();
    			echo "";
    		}
    	}
    }

    找到发送短信的函数:

    [代码]php代码:

    //发短信团购券
    function send_deal_coupon_sms($deal_coupon_id)
    {
    	if(app_conf("SMS_ON")==1&&app_conf("SMS_SEND_COUPON")==1)
    	{
    		$coupon_data = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."deal_coupon where id = ".$deal_coupon_id);				
    		if($coupon_data)
    		{
    			$forbid_sms = intval($GLOBALS['db']->getOne("select forbid_sms from ".DB_PREFIX."deal where id = ".$coupon_data['deal_id']));
    			if($forbid_sms==0)
    			{
    				$user_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$coupon_data['user_id']);
    				if($user_info['mobile']!='')
    				{
    					$tmpl = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."msg_template where name = 'TPL_SMS_COUPON'");				
    					$tmpl_content = $tmpl['content'];
    					$coupon_data['begin_time_format'] = $coupon_data['begin_time']==0?$GLOBALS['lang']['NO_BEGIN_TIME']:to_date($coupon_data['begin_time'],'Y-m-d');
    					$coupon_data['end_time_format'] = $coupon_data['end_time']==0?$GLOBALS['lang']['NO_END_TIME']:to_date($coupon_data['end_time'],'Y-m-d');			
    					$coupon_data['user_name'] = $user_info['user_name'];
    					$coupon_data['deal_name'] = $GLOBALS['db']->getOne("select name from ".DB_PREFIX."deal_order_item where id = ".$coupon_data['order_deal_id']);
    					$coupon_data['deal_sub_name'] = $GLOBALS['db']->getOne("select sub_name from ".DB_PREFIX."deal_order_item where id = ".$coupon_data['order_deal_id']);
    					$deal_id = $coupon_data['deal_id'];
    					if(!$coupon_data['deal_name']||!$coupon_data['deal_sub_name'])
    					{
    						$deal_info = $GLOBALS['db']->getRow("select name,sub_name from ".DB_PREFIX."deal where id = ".$deal_id);
    						if(!$coupon_data['deal_name'])
    						$coupon_data['deal_name'] = $deal_info['name'];
    						if(!$coupon_data['deal_sub_name'])
    						$coupon_data['deal_sub_name'] = $deal_info['sub_name'];
    					}					
    					$order_item = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."deal_order_item where id = ".intval($coupon_data['order_deal_id']));
    					$deal_type = intval($GLOBALS['db']->getOne("select deal_type from ".DB_PREFIX."deal where id = ".intval($order_item['deal_id'])));
    					if($deal_type == 1&&$order_item)
    					{
    						$coupon_data['deal_name'].= " ".$GLOBALS['lang']['BUY_NUMBER']."(".$order_item['number'].")";
    						$coupon_data['deal_sub_name'].= " ".$GLOBALS['lang']['BUY_NUMBER']."(".$order_item['number'].")";
    					}
    					
    	
    					$GLOBALS['tmpl']->assign("coupon",$coupon_data);
    					$msg = $GLOBALS['tmpl']->fetch("str:".$tmpl_content);
    					$msg_data['dest'] = $user_info['mobile'];
    					$msg_data['send_type'] = 0;
    					$msg_data['content'] = addslashes($msg);;
    					$msg_data['send_time'] = 0;
    					$msg_data['is_send'] = 0;
    					$msg_data['create_time'] = get_gmtime();
    					$msg_data['user_id'] = $user_info['id'];
    					$msg_data['is_html'] = $tmpl['is_html'];
    					$GLOBALS['db']->autoExecute(DB_PREFIX."deal_msg_list",$msg_data); //插入				
    				}
    			}
    		}		
    	}
    }

    将其修改为:

    [代码]php代码:

    //发短信团购券
    function send_deal_coupon_sms($deal_coupon_id)
    {
    	if(app_conf("SMS_ON")==1&&app_conf("SMS_SEND_COUPON")==1)
    	{
    		$coupon_data = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."deal_coupon where id = ".$deal_coupon_id);				
    		if($coupon_data)
    		{
    			$forbid_sms = intval($GLOBALS['db']->getOne("select forbid_sms from ".DB_PREFIX."deal where id = ".$coupon_data['deal_id']));
    			if($forbid_sms==0)
    			{
    				$user_info = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."user where id = ".$coupon_data['user_id']);
    				if($user_info['mobile']!='')
    				{
    					$tmpl = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."msg_template where name = 'TPL_SMS_COUPON'");				
    					$tmpl_content = $tmpl['content'];
    					$coupon_data['begin_time_format'] = $coupon_data['begin_time']==0?$GLOBALS['lang']['NO_BEGIN_TIME']:to_date($coupon_data['begin_time'],'Y-m-d');
    					$coupon_data['end_time_format'] = $coupon_data['end_time']==0?$GLOBALS['lang']['NO_END_TIME']:to_date($coupon_data['end_time'],'Y-m-d');			
    					$coupon_data['user_name'] = $user_info['user_name'];
    					$coupon_data['deal_name'] = $GLOBALS['db']->getOne("select name from ".DB_PREFIX."deal_order_item where id = ".$coupon_data['order_deal_id']);
    					$coupon_data['deal_sub_name'] = $GLOBALS['db']->getOne("select sub_name from ".DB_PREFIX."deal_order_item where id = ".$coupon_data['order_deal_id']);
    					$deal_id = $coupon_data['deal_id'];
    					if(!$coupon_data['deal_name']||!$coupon_data['deal_sub_name'])
    					{
    						$deal_info = $GLOBALS['db']->getRow("select name,sub_name from ".DB_PREFIX."deal where id = ".$deal_id);
    						if(!$coupon_data['deal_name'])
    						$coupon_data['deal_name'] = $deal_info['name'];
    						if(!$coupon_data['deal_sub_name'])
    						$coupon_data['deal_sub_name'] = $deal_info['sub_name'];
    					}					
    					$order_item = $GLOBALS['db']->getRow("select * from ".DB_PREFIX."deal_order_item where id = ".intval($coupon_data['order_deal_id']));
    					$deal_type = intval($GLOBALS['db']->getOne("select deal_type from ".DB_PREFIX."deal where id = ".intval($order_item['deal_id'])));
    					if($deal_type == 1&&$order_item)
    					{
    						$coupon_data['deal_name'].= " ".$GLOBALS['lang']['BUY_NUMBER']."(".$order_item['number'].")";
    						$coupon_data['deal_sub_name'].= " ".$GLOBALS['lang']['BUY_NUMBER']."(".$order_item['number'].")";
    					}
    					
    	
    					$GLOBALS['tmpl']->assign("coupon",$coupon_data);
    					$msg = $GLOBALS['tmpl']->fetch("str:".$tmpl_content);
    					$msg_data['dest'] = $user_info['mobile'];
    					$msg_data['send_type'] = 0;
    					$msg_data['content'] = addslashes($msg);;
    					$msg_data['send_time'] = 0;
    					$msg_data['is_send'] = 0;
    					$msg_data['create_time'] = get_gmtime();
    					$msg_data['user_id'] = $user_info['id'];
    					$msg_data['is_html'] = $tmpl['is_html'];
    					$GLOBALS['db']->autoExecute(DB_PREFIX."deal_msg_list",$msg_data); //插入	
    					
    					//获取刚刚插入的数据ID,并实现短信的发送
    					$send_sms_id = mysql_insert_id();
    					echo "";			
    				}
    			}
    		}		
    	}
    }

    有心人应该已经看出来了,在函数的末尾都加了这么一段话:

    [代码]php代码:

    //获取刚刚插入的数据ID,并实现短信的发送
    $send_sms_id = mysql_insert_id();
    echo "";			

    这个即是刚才在DealMsgListAction.class.php中定义的那个发送短信与邮件的函数。为什么写成这样子呢?我也尝试过用new这个class的方法,不过一直不能发送,于是就采用了这种iframe的形式,也就是客户端浏览器调用来发送。原因以后有时间在慢慢找。

    这个只是修改了团购的短信与邮件的发送,还有很多地方要修改,可以找到对应的发送函数,在其末尾加入这段即可。


    PHP技术交流QQ群:422137578

    除非注明,文章均为 PHP二次开发 原创,转载请注明本文地址:http://www.php2.cc/article-940-1.html

    相关阅读

    最新评论

    用户名:  *

    邮 箱:  *

    网 址: 注意加上“http://”哦!