Esempio n. 1
2
 public function run()
 {
     $model = new MailLog();
     //条件
     $criteria = new CDbCriteria();
     $accept = trim(Yii::app()->request->getParam('accept'));
     //收件人
     $subject = trim(Yii::app()->request->getParam('subject'));
     //主题
     $start_time = Yii::app()->request->getParam('start_time');
     $end_time = Yii::app()->request->getParam('end_time');
     $accept && $criteria->addSearchCondition('accept', $accept);
     $subject && $criteria->addSearchCondition('subject', $subject);
     $start_time && $criteria->compare('sendtime', '>=' . strtotime($start_time));
     $end_time && $criteria->compare('sendtime', '<=' . strtotime($end_time));
     $criteria->order = 't.id DESC';
     $count = $model->count($criteria);
     //分页
     $pages = new CPagination($count);
     $pages->pageSize = 20;
     $pages->applyLimit($criteria);
     //查询
     $result = $model->findAll($criteria);
     $this->controller->render('index', array('model' => $model, 'datalist' => $result, 'pagebar' => $pages));
 }
 /**
  * Send a multi-part HTML email.
  * 
  * @return bool
  */
 function sendHTML($to, $from, $subject, $htmlContent, $attachedFiles = false, $customheaders = false, $plainContent = false, $inlineImages = false)
 {
     if (parent::sendHTML($to, $from, $subject, $htmlContent, $attachedFiles = false, $customheaders = false, $plainContent = false, $inlineImages = false)) {
         $log = new MailLog();
         $log->To = $to;
         $log->From = $from;
         $log->Subject = $subject;
         $log->Body = $htmlContent;
         $log->Date = date('Y-m-d H:i:s');
         $log->write();
     } else {
         throw new Exception("Mail not accepted for delivery to {$to}");
     }
 }
 /**
  * 批量操作
  *
  */
 public function actionBatch()
 {
     if ($this->method() == 'GET') {
         $command = trim($_GET['command']);
         $ids = intval($_GET['id']);
     } else {
         if ($this->method() == 'POST') {
             $command = trim($_POST['command']);
             $ids = $_POST['id'];
         } else {
             $this->message('errorBack', Yii::t('admin', 'Only POST Or GET'));
         }
     }
     empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
     switch ($command) {
         case 'Delete':
             //删除邮件
             foreach ((array) $ids as $id) {
                 $maillogModel = MailLog::model()->findByPk($id);
                 if ($maillogModel) {
                     $maillogModel->delete();
                 }
             }
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
             break;
     }
     $this->message('success', Yii::t('admin', 'Batch Operate Success'), $this->createUrl('index'));
 }
Esempio n. 4
0
 /**
  * 判断数据是否存在
  * 
  * return \$this->model
  */
 public function loadModel()
 {
     if ($this->model === null) {
         if (isset($_GET['id'])) {
             $this->model = MailLog::model()->findbyPk($_GET['id']);
         }
         if ($this->model === null) {
             throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.'));
         }
     }
     return $this->model;
 }
Esempio n. 5
0
 public function run()
 {
     $ids = Yii::app()->request->getParam('id');
     $command = Yii::app()->request->getParam('command');
     empty($ids) && $this->controller->message('error', Yii::t('admin', 'No Select'));
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $criteria = new CDbCriteria();
     $criteria->addInCondition('id', $ids);
     switch ($command) {
         case 'delete':
             //删除
             MailLog::model()->deleteAll($criteria);
             break;
         default:
             $this->controller->message('error', Yii::t('admin', 'Error Operation'));
     }
     $this->controller->message('success', Yii::t('admin', 'Batch Operate Success'));
 }
Esempio n. 6
0
 /**
  * Send email to all customers according provided template id
  *
  * @access	public
  * @author	John.Meng(孟远螓) arzen1013@gmail.com 2009-4-4
  * @param	int	$id 	template id
  * @return	void
  */
 function sendMail($id)
 {
     $this->mail_msg = array();
     $mail_template = $this->read(null, $id);
     $mail_data = $mail_template['MailTemplate'];
     //-- import phpmailer
     App::import("Vendor", "PHPMailer", array('file' => 'PHPMailer' . DS . 'class.phpmailer.php'));
     //-- get all mail servers
     App::import('Model', 'Webmailler.MailServer');
     $mail_server_obj = new MailServer();
     $servers_list = $mail_server_obj->find('all');
     $servers = Set::extract($servers_list, '{n}.MailServer');
     //--- get all customers by page
     App::import('Model', 'Webmailler.MailCustomer');
     $mail_customer_obj = new MailCustomer();
     //--- log
     App::import('Model', 'Webmailler.MailLog');
     $mail_log_obj = new MailLog();
     $limit = count($servers);
     $total = $mail_customer_obj->find('count', array('conditions' => array('MailCustomer.mail_customer_category_id' => explode($this->group_splitor, $mail_data['to']))));
     $pages = ceil($total / $limit);
     $total = $success = $fail = 0;
     $charset = "UTF-8";
     if (Configure::read('Config.language') == "zh-CN") {
         $charset = "GBK";
     }
     for ($page = 1; $page <= $pages; $page++) {
         $conditions = array('fields' => array('MailCustomer.nickname', 'MailCustomer.gender', 'MailCustomer.email'), 'limit' => $limit, 'page' => $page, 'conditions' => array('MailCustomer.mail_customer_category_id' => explode($this->group_splitor, $mail_data['to'])));
         $customers_list = $mail_customer_obj->find('all', $conditions);
         $customers = Set::extract($customers_list, '{n}.MailCustomer');
         if (is_array($customers)) {
             foreach ($customers as $key => $customer) {
                 $server = $servers[$key];
                 $mail = new PHPMailer();
                 $mail->CharSet = $charset;
                 if ($server['ssl']) {
                     $mail->SMTPSecure = "ssl";
                 }
                 $mail->IsSMTP();
                 $mail->SMTPAuth = true;
                 $mail->Host = $server['host'];
                 if ($server['port'] > 0) {
                     $mail->Port = $server['port'];
                 }
                 $mail->Username = $server['account'];
                 $mail->Password = $server['passwd'];
                 //					$mail->AddReplyTo($server['account'],"JohnMeng");
                 $mail->From = $server['account'];
                 $mail->FromName = $mail_data["from"];
                 $mail->AddReplyTo($mail_data["from_name"], $mail_data["from"]);
                 $mail->Subject = $mail_data['subject'];
                 $contents = $this->_parseMailContent($mail_data['content'], $customer);
                 if ($charset != "UTF-8") {
                     $mail->Subject = $this->_utf8ToGBK($mail->Subject);
                     $contents = $this->_utf8ToGBK($contents);
                 }
                 if ($mail_data['plain_text']) {
                     $mail->Body = strip_tags($contents);
                 } else {
                     $contents = $this->_parseEmbedMedia($contents, $mail);
                     $mail->MsgHTML($contents);
                     $mail->AltBody = strip_tags($contents);
                 }
                 $mail->AddAddress($customer['email'], $customer['nickname']);
                 //-- add attachments
                 if ($mail_data['attachments']) {
                     $attachmens = explode($this->attachments_splitor, $mail_data['attachments']);
                     foreach ($attachmens as $attach) {
                         $mail->AddAttachment($attach);
                     }
                 }
                 $result = $mail->Send();
                 if (!$result) {
                     printf(__("Send to %s error: %s ", true) . "<br/>", $customer['email'], $mail->ErrorInfo);
                     $fail++;
                 } else {
                     printf(__("Send to %s done ", true) . "<br/>", $customer['email']);
                     $success++;
                 }
             }
         }
         $total++;
     }
     $log = sprintf(__("Sent Total:%s Success:%s Fail:%s ", true) . "\n", $total, $success, $fail);
     $mail_log_obj->log($mail_data['subject'] . "[{$log}]");
     echo nl2br($log);
     return $this->mail_msg;
 }
Esempio n. 7
0
 /**
  * 邮件发送
  * @param string $toemail
  * @param string $subject
  * @param string $message
  * @return boolean
  */
 public static function sendMail($toemail = '', $subject = '', $message = '')
 {
     $mailer = Yii::createComponent('application.extensions.mailer.EMailer');
     //邮件配置
     $mailer->SetLanguage('zh_cn');
     $mailer->Host = Yii::app()->params['emailHost'];
     //发送邮件服务器
     $mailer->Port = Yii::app()->params['emailPort'];
     //邮件端口
     $mailer->Timeout = Yii::app()->params['emailTimeout'];
     //邮件发送超时时间
     $mailer->ContentType = 'text/html';
     //设置html格式
     $mailer->SMTPAuth = true;
     $mailer->Username = Yii::app()->params['emailUserName'];
     $mailer->Password = Yii::app()->params['emailPassword'];
     $mailer->IsSMTP();
     $mailer->From = $mailer->Username;
     // 发件人邮箱
     $mailer->FromName = Yii::app()->params['emailFormName'];
     // 发件人姓名
     $mailer->AddReplyTo($mailer->Username);
     $mailer->CharSet = 'UTF-8';
     // 添加邮件日志
     $modelMail = new MailLog();
     $modelMail->accept = $toemail;
     $modelMail->subject = $subject;
     $modelMail->message = $message;
     $modelMail->send_status = 'waiting';
     $modelMail->save();
     // 发送邮件
     $mailer->AddAddress($toemail);
     $mailer->Subject = $subject;
     $mailer->Body = $message;
     if ($mailer->Send() === true) {
         $modelMail->times = $modelMail->times + 1;
         $modelMail->send_status = 'success';
         $modelMail->save();
         return true;
     } else {
         $error = $mailer->ErrorInfo;
         $modelMail->times = $modelMail->times + 1;
         $modelMail->send_status = 'failed';
         $modelMail->error = $error;
         $modelMail->save();
         return false;
     }
 }