From 40b58bda04cb76bd456aea318f7b80207cebf17d Mon Sep 17 00:00:00 2001 From: Jianxuan Li Date: Sat, 3 Jan 2015 22:29:35 +0800 Subject: [PATCH] add class Westdc\Mail\Queue --- Westdc/Mail/Queue.php | 41 +++++++++++++++++++++++++++++++++++++++++ Westdc/Mail/Sender.php | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 Westdc/Mail/Queue.php diff --git a/Westdc/Mail/Queue.php b/Westdc/Mail/Queue.php new file mode 100644 index 0000000..deeb13d --- /dev/null +++ b/Westdc/Mail/Queue.php @@ -0,0 +1,41 @@ +serviceManager = $serviceManager; + + $this->init(); + + return $this; + } + + private function init() + { + + } + + public function add(){ + + } + + public function show(){ + + } + +} \ No newline at end of file diff --git a/Westdc/Mail/Sender.php b/Westdc/Mail/Sender.php index e85f54f..b7c860c 100644 --- a/Westdc/Mail/Sender.php +++ b/Westdc/Mail/Sender.php @@ -24,6 +24,11 @@ class Sender implements ServiceManagerAwareInterface{ return $this; } + /** + * 发送即时邮件 + * @param $options + * @return bool + */ public function backend($options) { $cmd = "php ".CURRENT_BOOTSTRAP_SCRIPT; @@ -50,4 +55,36 @@ class Sender implements ServiceManagerAwareInterface{ return true; } + /** + * 将邮件添加到发送列队,降低内存和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; + } + } \ No newline at end of file