Ejemplo n.º 1
0
 public function actionCreate2()
 {
     $username = Yii::$app->user->identity->username;
     $users = User::find()->all();
     $scholars = Scholar::find()->all();
     $model2 = new Email();
     foreach ($users as $user) {
         foreach ($scholars as $scholar) {
             if ($user->username == $username && $user->id == $scholar->scholar_user_id) {
                 $model2->email_scholar_id = $scholar->scholar_id;
                 $model2->subject = "Low/Fail Grade";
                 if ($model2->load(Yii::$app->request->post())) {
                     if ($model->load(Yii::$app->request->post())) {
                         $to = "*****@*****.**";
                         $subject = "Low/Fail Grade";
                         $body = $model2->content . "\nfrom:" . $scholar->scholar_contact_email . PHP_EOL;
                         $headers = "from: root@localhost";
                         if (mail($to, $subject, $body, $headers)) {
                             \Yii::$app->getSession()->setFlash('error', 'The message is delivered');
                         } else {
                             \Yii::$app->getSession()->setFlash('error', 'Message failed');
                         }
                         return $this->redirect(['subject/index', 'id' => $model2->email_id]);
                         return $this->redirect(['create2', 'id' => $model2->email_id]);
                     } else {
                         return $this->render('create2', ['model2' => $model2]);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates a new Email model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Email();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 3
0
					

							<?php 
ActiveForm::end();
?>
							  <?php 
$username = Yii::$app->user->identity->username;
$users = User::find()->all();
$scholars = Scholar::find()->all();
$model2 = new Email();
foreach ($users as $user) {
    foreach ($scholars as $scholar) {
        if ($user->username == $username && $user->id == $scholar->scholar_user_id) {
            $model2->email_scholar_id = $scholar->scholar_id;
            $model2->subject = "Low/Fail Grade";
            if ($model2->load(Yii::$app->request->post())) {
                $to = "*****@*****.**";
                $subject = "Low/Fail Grade";
                $body = $model2->content . "\nfrom:" . $scholar->scholar_contact_email . PHP_EOL;
                $headers = "from: root@localhost";
                if (mail($to, $subject, $body, $headers)) {
                    \Yii::$app->getSession()->setFlash('error', 'The message is delivered');
                } else {
                    \Yii::$app->getSession()->setFlash('error', 'Message failed');
                }
            }
        }
    }
}
?>