M
M
MaikMain2021-10-02 11:15:26
Yii
MaikMain, 2021-10-02 11:15:26

Errors when sending messages via SMTP. Yii2?

Good afternoon. I've been sitting for the second day and I don't understand why I get errors: "Expected response code 250 but got code "550", with message "550 not local sender over smtp". I

provide the code.
Controller - CallbackController:

spoiler
<?php

namespace frontend\controllers;

use frontend\models\CallbackForm;
use Yii;

class CallbackController extends AppController
{
    public function actionIndex()
    {
        $model = new CallbackForm();
        if ($model->load(Yii::$app->request->post()) && $model->callback(Yii::$app->params['emailto'])) {
            Yii::$app->session->setFlash('callbackFormSubmitted');
            return $this->redirect(Yii::$app->request->referrer);
        } else {
            return $this->renderAjax('callback', [
                'model' => $model,
            ]);
        }
    }
}


The form:
spoiler
<?php

namespace frontend\models;

use yii\base\Model;
use Yii;

class CallbackForm extends Model
{
    public $name;
    public $phone;

    public function rules()
    {
        return [
            [['name', 'phone'], 'required'],
            [['name'], 'string', 'max' => 100],
            [['phone'], 'integer'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'callback';
    }

    public function attributeLabels()
    {
        return [
            'name' => 'Имя',
            'phone' => 'Телефон',
        ];
    }

    public function callback($emailto)
    {
        /* Проверяем форму на валидацию */
        if ($this->validate()) {
            Yii::$app->mailer->compose('valli/callback', [
                    'name' => $this->name,
                    'phone' => $this->phone,
                ])
                ->setFrom([Yii::$app->params['adminEmail']]) /* от кого */
                ->setTo(Yii::$app->params['emailto']) /* куда */
                ->setSubject('Заявка обратного звонка') /* тема отправителя */
                ->send(); /* функция отправки письма */
            return true;
        } else {
            return Yii::$app->session->setFlash('error', 'Ошибка при отправлении сообщения');
        }
    }
}


view:
spoiler
<?php $form = \yii\bootstrap\ActiveForm::begin(['id' => 'contact-form', 'action' => ['callback/index'],]); ?>
    <div class="popup-fos" ><span id="modal_close" class="close"></span>
        <p class="popup-fos__text">На какой номер вам позвонить?</p>
        <form action="" method="post" class="call_order_fos">
            <input type="text"  name="CallbackForm[name]" aria-required="true" aria-invalid="true" placeholder="Ваше имя" class="v-fld"/>
            <input type="tel" name="CallbackForm[phone]" aria-required="true" aria-invalid="true" value="" placeholder="Ваш телефон" class="v-fld"/>
            <?= \yii\helpers\Html::submitButton('Заказать звонок <span class="werg">мне!</span>', ['class' => 'v-darkbtn', 'name' => 'callback-button', 'id' => 'refreshButton',]) ?>
            <p>Нажимая, вы подтверждаете отправку персональных данных.</p>
        </form>
    </div>
<?php \yii\bootstrap\ActiveForm::end(); ?>


common/config/main-local.php (Username and password hidden, but they are 100% correct)
spoiler
'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.mail.ru',
                'username' => 'email',
                'password' => 'пароль',
                'port' => '465',
                'encryption' => 'SSL',
            ]
        ],


common/config/params.php
spoiler
<?php
return [
    'adminEmail' => 'емайл админа отправителя',
    'emailto' => 'емайл кому посылаем',
    'user.passwordResetTokenExpire' => 3600,
];


I received the password for external applications and put it in the password field. The admin e-mail and connection e-mail are the same.
I don't understand why it's throwing errors, please help. Thank you very much in advance.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
R
Ruslan, 2021-10-04
@Tiasar

Well, as if the answer is in the question - 550 not local sender over smtp No says such a user for SMTP, pick

'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.mail.ru',
                'username' => 'email',
                'password' => 'пароль',
                'port' => '465',
                'encryption' => 'SSL',
            ]

username - full specify? with a domain? I don’t know how to mail.ru, for a Google mail account, you must explicitly indicate that you can cling to SMTP, this is the second vector where there may be a problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question