yii2 mailer mail not sent

Multi tool use


yii2 mailer mail not sent
There are absolutely two identical methods for sending mail (registration of a new user, sending a letter to activate the user). One method is implemented in the console, and it works:
public function actionSendMessage()
{
$user = new User();
$this->readValue($user, 'username');
$this->readValue($user, 'login');
$this->readValue($user, 'email');
$user->hash_password = Yii::$app->getSecurity()->generatePasswordHash($this->prompt('password'));
$this->readValue($user, 'phone');
$this->readValue($user, 'address');;
$user->state = User::STATUS_WAIT;
$user->generateAuthKey();
$user->generateEmailConfirmToken();
if ($user->save()) {
Yii::$app->mailer->compose('@app/mail/emailConfirm', ['user' => $user])
->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])
->setTo($user->email)
->setSubject('Email confirmation for ' . Yii::$app->name)
->send();
}
}
The second must send a letter when registering on the site, but alas, the letter does not come (no errors):
public function sign()
{
$user = new User();
$user->username = $this->username;
$user->login = $this->login;
$user->email = $this->email;
$user->hash_password = yii::$app->security->generatePasswordHash($this->password);
$user->phone = $this->phone;
$user->address = $this->address;
$user->state = User::STATUS_WAIT;
$user->generateAuthKey();
$user->generateEmailConfirmToken();
if ($user->save()) {
Yii::$app->mailer->compose('@app/mail/emailConfirm', ['user' => $user])
->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name])
->setTo($user->email)
->setSubject('Email confirmation for ' . Yii::$app->name)
->send();
}
}
In what there can be an error? $user->save()
is work for both actions.
$user->save()
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.