add function of send email in backend
This commit is contained in:
parent
af4200c386
commit
0c31626c84
|
@ -20,5 +20,40 @@ class Tools {
|
|||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?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;
|
||||
|
||||
class Sender implements ServiceManagerAwareInterface{
|
||||
|
||||
protected $serviceManager;
|
||||
|
||||
public function setServiceManager(ServiceManager $serviceManager)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
||||
|
||||
}
|
Loading…
Reference in New Issue