public function actionSendMailQueue() { $criteria = new CDbCriteria(array('condition' => 'success=:success AND attempts < max_attempts', 'params' => array(':success' => 0))); $queueList = MailQueue::model()->findAll($criteria); foreach ($queueList as $queueItem) { $result = EmailHelper::sendEmail($queueItem->subject, $queueItem->to_email, $queueItem->message, $queueItem->from_email, $queueItem->from_name); if ($result) { $queueItem->attempts = $queueItem->attempts + 1; $queueItem->success = 1; $queueItem->last_attempt = time(); $queueItem->date_sent = time(); $queueItem->save(FALSE); } else { $queueItem->attempts = $queueItem->attempts + 1; $queueItem->last_attempt = time(); $queueItem->save(FALSE); } } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param string the username of the model to be loaded */ public function loadModel($id) { $model = MailQueue::model()->findByAttributes(array('id' => $id)); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function testGetStatusStr() { $model = MailQueue::model()->findByPk(1); $this->assertTrue($model != null); $this->assertTrue($model->statusStr == 'Pending'); }
public function add($post) { $model = new OrderMedlatec(); $model->setAttributes($post); //$order->time_meet = StringHelper::dateToTime($post['time_meet']); //$order->time_confirm = StringHelper::dateToTime($post['time_confirm']); $model->created_at = time(); $model->updated_at = time(); $model->time_meet = time(); $model->time_confirm = time(); if ($model->save(FALSE)) { MailQueue::model()->addMailQueue('Có một đơn đặt hàng mới dịch vụ medlatec', '*****@*****.**', 'meboo admin', '*****@*****.**', 'Có một đơn đặt hàng mới dịch vụ medlatec'); return $model->id; } return FALSE; }
/** * Sends pending mail messages. * @return void */ public static function sendMail() { // Prepare search criteria $criteria = new CDbCriteria(); $criteria->condition = 'status=' . self::STATUS_PENDING; $criteria->order = 'create_time ASC'; $criteria->limit = 5; // Look for pending email items $pendingItems = MailQueue::model()->findAll($criteria); // Walk through pending items foreach ($pendingItems as $email) { // Send email $result = @mail($email->recipient, $email->email_subject, $email->email_body, $email->email_headers); if ($result == true) { // Succeeded $email->status = self::STATUS_SENT; $email->sent_time = time(); } else { // Failed $email->status = self::STATUS_FAILED; Yii::log('Error sending email ', 'info'); } // Save changes to DB $email->save(); } }
public function actionActivate() { $request = Yii::app()->request; try { $token = StringHelper::filterString($request->getQuery('token')); if ($token != '') { $check = Provider::model()->findByAttributes(array('token' => $token)); if ($check) { $password = StringHelper::generateRandomString(5); $check->token = ''; $check->password = md5($password); $check->save('FALSE'); $subject = 'Mật khẩu tài khoản provider Meboo của bạn'; $to_email = $check->email; $from_email = '*****@*****.**'; $from_name = 'Hỗ trợ Meboo'; $message = 'Mật khẩu tài khoản Meboo Provider của bạn: ' . $password; MailQueue::model()->addMailQueue($message, $from_email, $from_name, $to_email, $subject); MailQueue::model()->addMailQueue('Có provider mới', $from_email, $from_name, '*****@*****.**', 'Có provider mới'); Yii::app()->user->setFlash('success', 'Vui lòng kiểm tra email để lấy mật khẩu đăng nhập'); $this->redirect(Yii::app()->createUrl('user/login')); } else { Yii::app()->user->setFlash('error', 'Token đã hết hạn !'); $this->redirect(Yii::app()->createUrl('user/login')); } } else { Yii::app()->user->setFlash('error', 'Token không tồn tại'); $this->redirect(Yii::app()->createUrl('user/login')); } } catch (Exception $ex) { ResponseHelper::JsonReturnError($ex->getMessage(), 'Error'); } }
public function add($post) { $model = new Provider(); $model->setAttributes($post); $model->active = 0; //MailQueue::model()->add(); if ($model->save(FALSE)) { MailQueue::model()->addMailQueue('Có một đơn vị cung cấp dịch vụ y tế đã đăng ký tới Meboo', '*****@*****.**', 'meboo admin', '*****@*****.**', 'Có một đơn đặt hàng mới dịch vụ medlatec'); return TRUE; } return FALSE; }