/** * Creates a new MedicalCertificate model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new MedicalCertificate(); if ($model->load(Yii::$app->request->post())) { //send email before saving in DB //get student info $student_id = $model->student_id; $student = Student::findOne($student_id); //get student's program $program = Program::findOne($student->program_id); //get Clinic that produce the Medical Certificate $clinic = Clinic::findOne($model->clinic_id); //get authorizer info $auth = Authorizer::findOne($model->au_id); $staff = Staff::findOne($auth->staff_id); $value = Yii::$app->mail->compose()->setFrom(array('*****@*****.**' => 'imaprog'))->setTo('*****@*****.**')->setSubject('Medical Certificate')->setHtmlBody(' Serial Number: ' . $model->mc_serial . ' Student Name: ' . $student->student_name . ' Student Matrix: ' . $student->student_matrix . ' Student Faculty: ' . $program->program_name . ' Problem/Diesease: ' . $model->mc_problem . ' Valid From: ' . $model->mc_startdate . ' Till: ' . $model->mc_enddate . ' Appointmet On: ' . $model->mc_appdate . ' Produced By: ' . $clinic->clinic_name . ' Authorize By: ' . $staff->staff_name)->send(); //save into DB $model->save(); //return to view, then proceed with sending email to the lecturers, NotifyEmailController.php return $this->redirect(['view', 'id' => $model->mc_id]); } else { return $this->renderAjax('create', ['model' => $model]); } }