diff --git a/Westdc/Helpers/Tools.php b/Westdc/Helpers/Tools.php index 949a88e..071479a 100644 --- a/Westdc/Helpers/Tools.php +++ b/Westdc/Helpers/Tools.php @@ -19,6 +19,41 @@ class Tools { public function isEmail($str){ return true; } + + /** + * @param $cmd + */ + public function execBackend($cmd) + { + if (substr(php_uname(), 0, 7) == "Windows"){ + pclose(popen("start cmd /c ". $cmd, "r")); + } + else { + exec($cmd . " > /dev/null &"); + } + + return; + } + + /** + * 返回的汉语文字信息在windows中是GB2312编码,需要手动改成UTF8 + * iconv("GB2312","UTF-8",$read); + * @param $cmd + * @return array + */ + public function execFront($cmd) + { + $response = array(); + $handle = popen("$cmd 2>&1", 'r'); + $read = ''; + while ($read = fread($handle, 20096)) { + $response[] = trim($read); + } + pclose($handle); + flush(); + + return $response; + } } \ No newline at end of file diff --git a/Westdc/Mail/Mail.php b/Westdc/Mail/Mail.php index eeb7cf4..b0a5590 100644 --- a/Westdc/Mail/Mail.php +++ b/Westdc/Mail/Mail.php @@ -8,7 +8,6 @@ namespace Westdc\Mail; -use Zend\Mime\Mime; use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManagerAwareInterface; use Westdc\EventModel\AbstractEventManager; @@ -16,6 +15,7 @@ use Westdc\Service\ServiceManager as WestdcServiceManager; use Zend\Mail\Message; use Zend\Mail\Transport\Smtp as SmtpTransport; use Zend\Mail\Transport\SmtpOptions; +use Zend\Mime\Mime; use Zend\Mime\Message as MimeMessage; use Zend\Mime\Part as MimePart; @@ -23,8 +23,6 @@ class Mail extends AbstractEventManager implements ServiceManagerAwareInterface{ protected $serviceManager; - private $db; - public $mail; public $config; public $subject; @@ -50,9 +48,6 @@ class Mail extends AbstractEventManager implements ServiceManagerAwareInterface{ $this->serviceManager = $serviceManager->getServiceManager(); } - $dbService = $this->serviceManager->get('Db'); - $this->db = $dbService->getPdo(); - $this->loadConfigure(); $this->smtp(); $this->buildMailMessage(); @@ -134,10 +129,9 @@ class Mail extends AbstractEventManager implements ServiceManagerAwareInterface{ $this->from = $from; } - //使用loadTemplate 的结果发送邮件 - //在此之前需要使用 $this->mail->addTo()添加收件人 - public function send($from = NULL){ + public function preSend($from = NULL) + { if(empty($this->subject) || empty($this->body)) { return "邮件信息不完整"; @@ -169,6 +163,16 @@ class Mail extends AbstractEventManager implements ServiceManagerAwareInterface{ $this->mail->setSubject($this->subject); + return true; + } + + //使用loadTemplate 的结果发送邮件 + //在此之前需要使用 $this->mail->addTo()添加收件人 + public function send($from = NULL){ + + if(!$status = $this->preSend($from)) + return $status; + try { $this->transport->send($this->mail); return true; diff --git a/Westdc/Mail/Sender.php b/Westdc/Mail/Sender.php new file mode 100644 index 0000000..2099440 --- /dev/null +++ b/Westdc/Mail/Sender.php @@ -0,0 +1,47 @@ +serviceManager = $serviceManager; + + return $this; + } + + 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'); + //$tools->execBackend($cmd); + //echo $cmd; + //var_dump($tools->execFront($cmd)); + //exit(); + return true; + } + +} \ No newline at end of file diff --git a/Westdc/Mail/Template.php b/Westdc/Mail/Template.php index f2280d0..e369f19 100644 --- a/Westdc/Mail/Template.php +++ b/Westdc/Mail/Template.php @@ -25,7 +25,6 @@ class Template implements ServiceManagerAwareInterface { $dbService = $this->serviceManager->get('Db'); $this->db = $dbService->getPdo(); - } public function fetchAll() @@ -94,11 +93,10 @@ class Template implements ServiceManagerAwareInterface } $rs=$this->db->query($sql); + return $rs->fetch(); } -<<<<<<< HEAD -======= /** * @param $key * @param $data @@ -137,6 +135,5 @@ class Template implements ServiceManagerAwareInterface ]; }//function load ->>>>>>> 91044298c8430244e78f4e502aa5d9d0ce84a3f8 } \ No newline at end of file