Config mail.ru smtp

This commit is contained in:
iIronside 2023-10-18 10:48:38 +03:00
parent 5469a209a5
commit 233a8a6d10
9 changed files with 53 additions and 20 deletions

View File

@ -1,4 +1,4 @@
<?php <?php
return [ return [
'adminEmail' => 'supp0rt.friday@yandex.ru', 'adminEmail' => 'chancellery@itguild.info',
]; ];

View File

@ -1,9 +1,9 @@
<?php <?php
return [ return [
'adminEmail' => 'supp0rt.friday@yandex.ru', 'adminEmail' => 'chancellery@itguild.info',
'supportEmail' => 'supp0rt.friday@yandex.ru', 'supportEmail' => 'chancellery@itguild.info',
'senderEmail' => 'supp0rt.friday@yandex.ru', 'senderEmail' => 'chancellery@itguild.info',
'senderName' => 'Friday.support mailer', 'senderName' => 'Chancellery ITguild mailer',
'user.passwordResetTokenExpire' => 3600, 'user.passwordResetTokenExpire' => 3600,
'user.passwordMinLength' => 8, 'user.passwordMinLength' => 8,
]; ];

View File

@ -0,0 +1,10 @@
<?php
/* @var $this yii\web\View */
/* @var $user common\models\User */
?>
Hello <?= $user->username ?>,
You have successfully registered!

View File

@ -0,0 +1,10 @@
<?php
/* @var $this yii\web\View */
/* @var $user common\models\User */
?>
Hello <?= $user->username ?>,
You have successfully registered!

View File

@ -1,4 +1,4 @@
<?php <?php
return [ return [
'adminEmail' => 'supp0rt.friday@yandex.ru', 'adminEmail' => 'chancellery@itguild.info',
]; ];

View File

@ -8,7 +8,7 @@ $params = array_merge(
return [ return [
'id' => 'app-frontend', 'id' => 'app-frontend',
'name' => 'Guild', 'name' => 'itGuild',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'bootstrap' => ['log'], 'bootstrap' => ['log'],
'controllerNamespace' => 'frontend\controllers', 'controllerNamespace' => 'frontend\controllers',

View File

@ -1,4 +1,4 @@
<?php <?php
return [ return [
'adminEmail' => 'supp0rt.friday@yandex.ru', 'adminEmail' => 'chancellery@itguild.info',
]; ];

View File

@ -45,24 +45,15 @@ class ContactForm extends Model
/** /**
* Sends an email to the specified email address using the information collected by this model. * Sends an email to the specified email address using the information collected by this model.
* *
* @param string $email the target email address
* @return bool whether the email was sent * @return bool whether the email was sent
*/ */
public function sendEmail($email) public function sendEmail()
{ {
return Yii::$app->mailer->compose() return Yii::$app->mailer->compose()
->setTo($this->email) ->setTo($this->email)
->setFrom([Yii::$app->params['senderEmail'] => Yii::$app->params['senderName']]) ->setFrom([Yii::$app->params['senderEmail'] => Yii::$app->params['senderName']])
// ->setReplyTo([$this->email => $this->name])
->setSubject($this->subject) ->setSubject($this->subject)
->setTextBody($this->body) ->setTextBody($this->body)
->send(); ->send();
// return Yii::$app->mailer->compose()
// ->setTo($email)
// ->setFrom([$this->email => $this->name])
// ->setSubject($this->subject)
// ->setTextBody($this->body)
// ->send();
} }
} }

View File

@ -59,7 +59,29 @@ class SignupForm extends Model
$auth = Yii::$app->authManager; $auth = Yii::$app->authManager;
$authorRole = $auth->getRole('user'); $authorRole = $auth->getRole('user');
$auth->assign($authorRole, $user->id); $auth->assign($authorRole, $user->id);
return $user->save() ? $user : null; if ($user->save()) {
$this->sendEmail($user);
return $user;
} else {
return null;
}
}
/**
* Sends an email with a link, for resetting the password.
*
* @return bool whether the email was send
*/
private function sendEmail(User $user)
{
return Yii::$app->mailer->compose(
['html' => 'signup-html', 'text' => 'signup-text'],
['user' => $this]
)
->setFrom([Yii::$app->params['senderEmail'] => Yii::$app->name . ' robot'])
->setTo($user->email)
->setSubject('Account registration at ' . Yii::$app->name)
->send();
} }
} }