2014-12-24 16:38:23 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Created by PhpStorm.
|
|
|
|
|
* User: Li Jianxuan
|
|
|
|
|
* Date: 14-9-19
|
|
|
|
|
* Time: 下午3:43
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Westdc\Mail;
|
|
|
|
|
|
|
|
|
|
use Zend\ServiceManager\ServiceManager;
|
|
|
|
|
use Zend\ServiceManager\ServiceManagerAwareInterface;
|
2015-01-04 05:57:48 +00:00
|
|
|
|
use Westdc\Service\ServiceManager as WestdcServiceManager;
|
2014-12-24 16:38:23 +00:00
|
|
|
|
|
|
|
|
|
class Sender implements ServiceManagerAwareInterface{
|
|
|
|
|
|
|
|
|
|
protected $serviceManager;
|
|
|
|
|
|
2015-01-02 15:11:09 +00:00
|
|
|
|
public $debug = 0;
|
|
|
|
|
|
2014-12-24 16:38:23 +00:00
|
|
|
|
public function setServiceManager(ServiceManager $serviceManager)
|
|
|
|
|
{
|
|
|
|
|
$this->serviceManager = $serviceManager;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-04 05:57:48 +00:00
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
if(!$this->serviceManager instanceof ServiceManager)
|
|
|
|
|
{
|
|
|
|
|
$serviceManager = new WestdcServiceManager();
|
|
|
|
|
$this->serviceManager = $serviceManager->getServiceManager();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-03 14:29:35 +00:00
|
|
|
|
/**
|
|
|
|
|
* 发送即时邮件
|
|
|
|
|
* @param $options
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2014-12-24 16:38:23 +00:00
|
|
|
|
public function backend($options)
|
|
|
|
|
{
|
|
|
|
|
$cmd = "php ".CURRENT_BOOTSTRAP_SCRIPT;
|
|
|
|
|
$cmd .= ' mail send';
|
|
|
|
|
$cmd .= ' --email="'.$options['email'].'"';
|
|
|
|
|
$cmd .= ' --name="'.$options['name'].'"';
|
|
|
|
|
$cmd .= ' --template="'.$options['template'].'"';
|
|
|
|
|
|
|
|
|
|
if(isset($options['data']))
|
|
|
|
|
{
|
|
|
|
|
$data = json_encode($options['data']);
|
|
|
|
|
$cmd .= ' --data=\''.$data.'\'';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tools = $this->serviceManager->get('Tools');
|
2015-01-02 15:11:09 +00:00
|
|
|
|
|
|
|
|
|
if($this->debug == 0)
|
|
|
|
|
{
|
|
|
|
|
$tools->execBackend($cmd);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var_dump($tools->execFront($cmd));
|
2014-12-24 16:38:23 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-03 14:29:35 +00:00
|
|
|
|
/**
|
|
|
|
|
* 将邮件添加到发送列队,降低内存和cpu消耗,但是用户无法即时收到,适用于通知类型的邮件和大批量发送的邮件
|
|
|
|
|
* @param $options
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function queue($options)
|
|
|
|
|
{
|
|
|
|
|
$cmd = "php ".CURRENT_BOOTSTRAP_SCRIPT;
|
|
|
|
|
$cmd .= ' mail queue';
|
|
|
|
|
$cmd .= ' --email="'.$options['email'].'"';
|
|
|
|
|
$cmd .= ' --name="'.$options['name'].'"';
|
|
|
|
|
$cmd .= ' --template="'.$options['template'].'"';
|
|
|
|
|
|
|
|
|
|
if(isset($options['data']))
|
|
|
|
|
{
|
|
|
|
|
$data = json_encode($options['data']);
|
|
|
|
|
$cmd .= ' --data=\''.$data.'\'';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tools = $this->serviceManager->get('Tools');
|
|
|
|
|
|
|
|
|
|
if($this->debug == 0)
|
|
|
|
|
{
|
|
|
|
|
$tools->execBackend($cmd);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var_dump($tools->execFront($cmd));
|
|
|
|
|
return true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-24 16:38:23 +00:00
|
|
|
|
}
|