Answer the question
In order to leave comments, you need to log in
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:
<?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,
]);
}
}
}
<?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', 'Ошибка при отправлении сообщения');
}
}
}
<?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(); ?>
'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',
]
],
<?php
return [
'adminEmail' => 'емайл админа отправителя',
'emailto' => 'емайл кому посылаем',
'user.passwordResetTokenExpire' => 3600,
];
Answer the question
In order to leave comments, you need to log in
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',
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question