here is the actual setting itself

'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@common/mail', 'useFileTransport' => false, 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => 'smtp.yandex.ru', 'username' => 'test@prioriticlub.ru', 'password' => 'password', 'port' => '587', 'encryption' => 'TLS', ], ], 

I get this answer

 Expected response code 250 but got code "553", with message "553 5.7.1 Sender address rejected: not owned by auth user." 

what am I doing wrong

    1 answer 1

    I found this solution:

    In the configuration file web.php the following code:

     'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@app/mail', 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => 'smtp.yandex.ru', 'username' => 'test@yandex.ru', 'password' => '**********', 'port' => 465, 'encryption' => 'ssl', ], 'useFileTransport' => false, ], 

    In the model ContactForm.php I prescribed:

     public function contact($email) { $content = "<p>Email: " . $this->email . "</p>"; $content .= "<p>Name: " . $this->name . "</p>"; $content .= "<p>Subject: " . $this->subject . "</p>"; $content .= "<p>Body: " . $this->body . "</p>"; if ($this->validate()) { Yii::$app->mailer->compose("@app/mail/layouts/html", ["content" => $content]) ->setTo('test@yandex.ru') ->setFrom([\Yii::$app->params['supportEmail'] => $this->name]) ->setSubject($this->subject) ->setTextBody($this->body) ->send(); return true; } return false; } 

    In params.php:

     return [ 'adminEmail' => 'test@yandex.ru', 'supportEmail' => 'test@yandex.ru', ]; 

    In SiteController.php:

     public function actionContact() { /* Создаем экземпляр класса */ $model = new ContactForm(); /* получаем данные из формы и запускаем функцию отправки contact, если все хорошо, выводим сообщение об удачной отправке сообщения на почту */ if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) { Yii::$app->session->setFlash('contactFormSubmitted'); return $this->refresh(); /* иначе выводим форму обратной связи */ } else { return $this->render('contact', [ 'model' => $model, ]); } } 

    That's all.