Answer the question
In order to leave comments, you need to log in
How to create an email alert?
Actually I use yii2-swiftmailer, according to the documentation I saw an example:
$message = Yii::$app->mailer->compose();
if (Yii::$app->user->isGuest) {
$message->setFrom('[email protected]')
} else {
$message->setFrom(Yii::$app->user->identity->email)
}
$message->setTo(Yii::$app->params['adminEmail'])
->setSubject('Message subject')
->setTextBody('Plain text content')
->send();
public function actionClose($id)
{
$model = $this->findModel($id);
if(Yii::$app->user->identity->id==$model->author_id){
$model = new StatusTicket();
$model -> status_id = 6;
$model -> ticket_id = $id;
$message = Yii::$app->mailer->compose();
if ($model -> save())
Yii::$app->session->setFlash('success','<p>Заявка закрыта</p>');
return $this->redirect(['view', 'id' => $id]);
}
else
return $this->redirect(['view', 'id' => $id]);
}
Answer the question
In order to leave comments, you need to log in
Format the code. Don't forget to put semicolons.
if ($model -> save()) {
$message = Yii::$app->mailer->compose();
if (Yii::$app->user->isGuest) {
$message->setFrom('[email protected]');
} else {
$message->setFrom(Yii::$app->user->identity->email);
}
$mail = $message->setTo(Yii::$app->params['adminEmail'])
->setSubject('Message subject')
->setTextBody('Plain text content');
if ($mail->send()) {
Yii::$app->session->setFlash('success','<p>Заявка закрыта</p>');
} else {
Yii::$app->session->setFlash('error','<p>Ашибка</p>');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question