예제 #1
0
 /**
  * Update Email Templates
  * @return mixed
  */
 public function actionEmails($id = null)
 {
     $id = $id == null ? 1 : $id;
     $model = $id == 0 ? new EmailTemplates() : EmailTemplates::findOne($id);
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             Yii::$app->session->setFlash('success', $model->isNewRecord ? 'Created new template!' : 'Template Successfully Updated!');
             // form inputs are valid, do something here
             $model->save();
         }
     }
     return $this->render('emailtemplates', ['model' => $model]);
 }
예제 #2
0
 /**
  * Send email, replacing predefined model content with given $params
  * @param string $to
  * @param string $template
  * @param array $params
  */
 public function sendMail($to, $template_id, $params = [])
 {
     $template = \app\models\EmailTemplates::findOne($template_id);
     Yii::$app->mailer->compose('@app/mail/templates/content', ['body' => $template->body, 'params' => $params])->setFrom(['*****@*****.**' => 'Kid Crossing'])->setTo($to)->setSubject($template->subject)->send();
 }
예제 #3
0
 /**
  * Finds the EmailTemplates model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return EmailTemplates the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = EmailTemplates::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }