public function actionRegistermagain() { $magazin = new FMagazin(); if ($magazin->load(Yii::$app->request->post())) { \date_default_timezone_set('Asia/Ho_Chi_Minh'); $magazin->create_at = date('Y-m-d'); $magazin->Day = -1; $old_magazin = FMagazin::find()->where(['email' => $magazin->email])->one(); if ($old_magazin) { Yii::$app->session->setFlash('error-magazin', Yii::t('frontend', 'You registed email {0}.', $magazin->email)); $this->redirect(\Yii::$app->request->getReferrer()); } else { $contentmagazin = FContentMagazin::findOne(['Day' => 0, 'Level' => $magazin->level]); if (!$contentmagazin) { Yii::$app->session->setFlash('error-magazin', Yii::t('magazin', 'Sorry! We haven\'t excersice for you. We will send later')); $magazin->save(); $this->redirect(\Yii::$app->request->getReferrer()); } $message = Yii::$app->mailer->compose('@common/mail/register_magazin', ['contentmagazin' => $contentmagazin, 'magazin' => $magazin]); $message->setTo($magazin->email)->setFrom([Yii::$app->params['salesEmail'] => 'Magin Gam LTD'])->setSubject($contentmagazin->Subject); if ($message->send()) { //die('Hello'); $magazin->Day++; $magazin->save(); Yii::$app->session->setFlash('success-magazin', Yii::t('frontend', 'Thank your register. The first exercise sent your email!')); } else { Yii::$app->session->setFlash('error-magazin', Yii::t('frontend', 'There was an error sending email.')); } $this->redirect(\Yii::$app->request->getReferrer()); } } }
public function actionDay() { $magazins = CMagazin::find()->all(); $succes = 0; $fail = 0; $limit_mail = FConfigParam::find()->where(['name' => 'NUMBER_MAIL_MAGAZIN'])->one(); if ($limit_mail) { $limit_mai = $limit_mail->value; } else { $limit_mai = 7; } foreach ($magazins as $magazin) { if ($magazin->Day >= -1 && $magazin->Day < $limit_mai) { $contentmagazin = FContentMagazin::findOne(['Day' => $magazin->Day + 1, 'Level' => $magazin->level]); if ($contentmagazin) { $message = Yii::$app->mailer->compose('@common/mail/send_day_magazin', ['contentmagazin' => $contentmagazin, 'magazin' => $magazin]); //$message->attach(dirname(dirname(__DIR__)).'/frontend/web/files/'.$magazin->level.'-'.$magazin->getDaytoNow().'.docx'); $message->setTo($magazin->email)->setFrom([Yii::$app->params['salesEmail'] => 'Magin Gam LTD'])->setSubject('Bài tập dành cho buổi ' . $magazin->getDaytoNow() . ' sau đăng ký'); if ($message->send()) { $magazin->Day++; $magazin->save(); $succes++; } else { $fail++; } } } } return 'Thành công: ' . $succes . '- Thất bại: ' . $fail; }