public function api_create($email) { $model = new Subscriber(['email' => $email]); if ($model->save()) { return ['result' => 'success', 'error' => false]; } else { return ['result' => 'error', 'error' => $model->getErrors()]; } }
public function actionUnsubscribe($email) { if ($email && filter_var($email, FILTER_VALIDATE_EMAIL)) { Subscriber::deleteAll(['email' => $email]); echo '<h1>' . Yii::t('easyii/subscribe/api', 'You have successfully unsubscribed!') . '</h1>'; } else { throw new \yii\web\BadRequestHttpException(Yii::t('easyii/subscribe/api', 'Incorrect E-mail')); } }
public function dbInstall() { $db = Yii::$app->db; $tableOptions = null; if ($db->driverName === 'mysql') { $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=MyISAM'; } $db->createCommand()->createTable(Subscriber::tableName(), ['subscriber_id' => 'pk', 'email' => Schema::TYPE_STRING . '(128) NOT NULL', 'ip' => Schema::TYPE_STRING . '(16) NOT NULL', 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'"], $tableOptions)->execute(); $db->createCommand()->createTable(History::tableName(), ['history_id' => 'pk', 'subject' => Schema::TYPE_STRING . '(128) NOT NULL', 'body' => Schema::TYPE_TEXT . ' NOT NULL', 'sent' => Schema::TYPE_INTEGER . " DEFAULT '0'", 'time' => Schema::TYPE_INTEGER . " DEFAULT '0'"], $tableOptions)->execute(); }
private function send($model) { $text = $model->body . "<br><br>" . "--------------------------------------------------------------------------------"; foreach (Subscriber::find()->all() as $subscriber) { $unsubscribeLink = '<br><a href="' . Url::to(['/admin/subscribe/send/unsubscribe', 'email' => $subscriber->email], true) . '" target="_blank">' . Yii::t('easyii/subscribe', 'Unsubscribe') . '</a>'; if (Yii::$app->mailer->compose()->setFrom(Setting::get('robot_email'))->setTo($subscriber->email)->setSubject($model->subject)->setHtmlBody($text . $unsubscribeLink)->setReplyTo(Setting::get('admin_email'))->send()) { $model->sent++; } } return $model->save(); }
public function down() { $this->dropTable(models\Admin::tableName()); $this->dropTable(models\LoginForm::tableName()); $this->dropTable(models\Module::tableName()); $this->dropTable(models\Photo::tableName()); $this->dropTable(models\Setting::tableName()); $this->dropTable(Carousel::tableName()); $this->dropTable(catalog\models\Category::tableName()); $this->dropTable(catalog\models\Item::tableName()); $this->dropTable(article\models\Category::tableName()); $this->dropTable(article\models\Item::tableName()); $this->dropTable(Feedback::tableName()); $this->dropTable(File::tableName()); $this->dropTable(gallery\models\Category::tableName()); $this->dropTable(Guestbook::tableName()); $this->dropTable(News::tableName()); $this->dropTable(Page::tableName()); $this->dropTable(Subscriber::tableName()); $this->dropTable(History::tableName()); $this->dropTable(Text::tableName()); }