Почему не работает отправка письма на почту?

Модель
<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "backcall".
 *
 * @property int $id
 * @property string|null $name
 * @property string|null $telephone
 * @property string|null $email
 * @property string|null $date_request
 * @property string|null $date_response
 */
class Backcall extends \yii\db\ActiveRecord
{
    public $verifyCode;

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

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['date_request', 'date_response'], 'safe'],
            [['name', 'telephone', ], 'string', 'max' => 255],
            ['email', 'email'],
            ['verifyCode', 'captcha'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ИД',
            'name' => 'Ваше имя',
            'telephone' => 'Номер телефона',
            'email' => 'Почта',
            'date_request' => 'Время создания запроса',
            'date_response' => 'Время ответа запроса',
            'verifyCode' => 'Код подтверждения',
        ];
    }

    public function contact($email)
    {
        Yii::$app->mailer->compose()
            ->setTo($email)
            ->setFrom([Yii::$app->params['senderEmail'] => Yii::$app->params['senderName']])
            ->setReplyTo([$this->email => $this->name])
            ->setSubject($this->subject)
            ->setTextBody($this->body)
            ->send();
    }
}


Контроллер
public function actionCreate()
    {
        $model = new Backcall();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $model->contact(Yii::$app->params['adminEmail']);
            return $this->redirect(['site/index']);
        }

        return $this->render('create', [
            'model' => $model,
        ]);
    }


Представление
<?php

use yii\helpers\Html;
use yii\captcha\Captcha;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model app\models\Backcall */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="backcall-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'telephone')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
        'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
    ]) ?>

    <div class="form-group">
        <?= Html::submitButton('Отправить заявку', ['class' => 'button']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>


web
'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => false,
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.yandex.ru',
                'username' => 'damirshaniyazov@yandex.ru',
                'password' => 'parol',
                'port' => '465',
                'encryption' => 'ssl',
            ]
        ],


параметры
return [
    'adminEmail' => 'damirshaniyazov@yandex.ru',
    'senderEmail' => 'damirshaniyazov@yandex.ru',
    'senderName' => 'Дамир Шаниязов,
];


Что я не так делаю? Вроде бы всё верно настроил. Ошибок нет (ну только валидация не работает в метода контакт модели бэкколл и то я убрал)
  • Вопрос задан
  • 40 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы